尖括号部分在 C# 中被称为什么,例如一些方法名<ISomething>()
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 :我知道尖括号的名称,但那部分是什么意思?方法的generiticisim?
更新 : 例如
我们会读
public Complex SomeMethodName(int x, int y, ....)
as public 方法 SomeMethodName 返回 Complex 作为结果并采用参数 int x, int y, ...
我们应该读
public Complex SomeMethodName<ISomething>(int x, int y, ....)
as public 泛型 ISomething 的方法 SomeMethodName 返回 Complex 作为结果并采用参数 int x, int y, ... ?
模板类型。
模板类型名。
模板参数。
模板参数。
My question is what is the name for 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
这篇 Link 解释了泛型方法。
在 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 :我知道尖括号的名称,但那部分是什么意思?方法的generiticisim?
更新 : 例如 我们会读
public Complex SomeMethodName(int x, int y, ....)
as public 方法 SomeMethodName 返回 Complex 作为结果并采用参数 int x, int y, ...
我们应该读
public Complex SomeMethodName<ISomething>(int x, int y, ....)
as public 泛型 ISomething 的方法 SomeMethodName 返回 Complex 作为结果并采用参数 int x, int y, ... ?
模板类型。 模板类型名。 模板参数。 模板参数。
My question is what is the name for 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
这篇 Link 解释了泛型方法。