无法比较来自 C#

问题描述

我创建了一个字符串扩展方法

 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())