c# - VB.net 到 C# 等效于 "AddressOf"

标签 c# vb.net addressof

我正在尝试实现这个例子

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

但我面临的唯一问题是无法在 C#.net 中转换的 VB.net 的 AddressOf 关键字

谁能帮我解决这个问题,我应该使用什么替代方案来让它工作。

谢谢。

编辑:我在 stackoverflow 上发现了一些关于类似问题的搜索,但我无法理解它们。

最佳答案

你可以忽略它。方法组可隐式转换为 C# 中的委托(delegate)。

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

或者更简单(我认为这需要 C# 2):

return ResultStr.Replace(InputTxt, ReplaceWords);

但由于 ReplaceWords 非常简单,我会考虑使用 lambda 表达式(需要 C# 3):

return ResultStr.Replace(InputTxt, m => "<span class=highlight>" + m + "</span>");

关于c# - VB.net 到 C# 等效于 "AddressOf",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7725511/

相关文章:

c# - 在 GridControl PrintPreview 中显示行号

c# - 在没有 Excel 和 OLEDB 的情况下读取 .xlsx

vb.net - 对象的类型初始值设定项引发异常

vb.net - Application Insights 在加载时因 System.Reflection.TargetInvocationException 失败 - WP 8.1

c++ - 地址 (&) 和间接运算符的正确格式是什么

c# - 从 Visual Studio 中的 C# 代码传递到 C 代码

c# - Foreach 扩展的更优雅的 LINQ 替代方案

sql - 从 SQL Server 表填充和编辑数据网格

c++ - 在像 ostream& 运算符 <<(...) 这样的类名之后使用的 & 符号是什么?

c - 将 “pointer to pointer” 和 “address of pointer” 传递给函数之间的区别