问题描述
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"
我不明白为什么,因为这个扩展方法返回一个字符串,所以逻辑上我可以将结果与字符串进行比较?
解决方法
您必须添加括号才能进行方法调用
if(Id.ShortID() == IdDest.ShortID())