【发布时间】:2021-04-07 22:43:48
【问题描述】:
我创建了一个字符串扩展方法
public static string ShortID(this string id)
{
return id.Substring(5);
}
当我想使用这样的扩展方法比较两个字符串时
if(Id.ShortID == IdDest.ShortID)
我有一个错误:
CS0019: impossible to apply operator == to operands of type "group of methods" and "group of methods"
我不明白为什么,因为这个扩展方法返回一个字符串,逻辑上我可以将结果作为字符串比较 no ?
【问题讨论】:
-
如果方法名后面不加括号,那只是方法组名,不是实际的方法调用。查看重复项。
标签: c# string compare extension-methods string-comparison