c# – 解析器前端的泛型和挑战

如果你有:
F(G<A,B>(4));

这是否意味着用户想要通过比较G和A产生的2个参数来调用方法F,而B和常数4?

或者是否表示调用F,使用类型参数A和B调用通用方法G,参数为4?

解决方法

所以我试过了,只是为了确定.事实证明这个工作很好:
void F(int x) { }
int G<T,U>(int x) { return x; }

class A { }
class B { }

void Main()
{
    F(G<A,B>(4));
}

但是这会产生一些编译错误

void F(bool x,bool y) { }

void Main()
{
    int G = 0,A = 1,B = 2;
    F(G<A,B>(4));
}

The type or namespace name ‘A’ Could not be found (press F4 to add a using directive or assembly reference)

The type or namespace name ‘B’ Could not be found (are you missing a using directive or an assembly reference?)

The variable ‘G’ is not a generic method. If you intended an expression list,use parentheses around the < expression.

所以答案是表达式F(G 函数调用.有许多方法强制编译器将其视为两个参数的单个函数调用:f(g (4))或F(G> A,B>(4)),仅举几个例子.

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...