Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.net to C# Equivalent of "AddressOf"

I am trying to implement this example

http://blog.evonet.com.au/post/Gridview-with-highlighted-search-results.aspx

but the only problem I am facing is the AddressOf keyword of VB.net which I am unable to convert in C#.net

can anybody help me out with this, what alternative I should use to make it work.

Thanks.

Edit: I found some searches on stackoverflow regarding similar problems but I am unable to understand them.

like image 696
Ahmed Avatar asked Dec 16 '22 08:12

Ahmed


1 Answers

You can just leave it out. Method groups are implicitly convertible to delegates in C#.

return ResultStr.Replace(InputTxt, new MatchEvaluator(ReplaceWords))

Or even simpler(I think this requires C# 2):

return ResultStr.Replace(InputTxt, ReplaceWords);

But since ReplaceWords is so simple, I'd consider a lambda expression(Requires C# 3):

return ResultStr.Replace(InputTxt, m => "<span class=highlight>" + m + "</span>");
like image 169
CodesInChaos Avatar answered Jan 02 '23 06:01

CodesInChaos