VB.net to C# Equivalent of “AddressOf”

后端 未结 4 525
囚心锁ツ
囚心锁ツ 2021-01-19 05:17

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 Ad

4条回答
  •  天涯浪人
    2021-01-19 05:43

    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 => "" + m + "");
    

提交回复
热议问题