[英]What do greater/less than sign (e.g. Action<List<X>>) mean in C#?
[英]What is the angle brackets part is called in C# e.g. SomeMethodName<ISomething>()
在C#中给出以下内容:
public Complex SomeMethodName<ISomething>(int x, int y, ....)
我们可以将每个部分描述如下:
public : accessor specifier
Complex : the resut of the function
SomeMethodName : Method Name
<ISomething> : ???
(int x, int y, ....) : parameter list
我的问题是<ISomething>
部分的名称是什么?
PS:我知道尖括号的名称,但是那部分代表什么? 该方法的起源?
更新 :例如,我们将阅读
public Complex SomeMethodName(int x, int y, ....)
作为公共方法SomeMethodName返回Complex作为结果并采用参数int x,int y,...
我们应该读
public Complex SomeMethodName<ISomething>(int x, int y, ....)
作为公用方法ISomething的公共方法SomeMethodName,返回Complex作为结果并采用参数int x,int y,...?
我的问题是Part的名字是什么?
是泛型方法的类型参数。
例如:
static void Swap<T>(ref T lhs, ref T rhs)
{
T temp;
temp = lhs;
lhs = rhs;
rhs = temp;
}
上面定义的方法被调用并替换为所需的类型:
public static void TestSwap()
{
int a = 1;
int b = 2;
Swap<int>(ref a, ref b);
System.Console.WriteLine(a + " " + b);
}
因此,在上面的Swap<int>
,我们正在传递类型参数int
该链接介绍了通用方法。
模板类型。 模板类型名称。 模板参数。 模板参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.