我曾多次看到ReSharper生成的代码如下所示:
delegate void myHandler(int i);
myHandler myHandlerContainer;
...
foreach (Delegate @delegate in myHandlerContainer.GetInvocationList())
{...}
Run Code Online (Sandbox Code Playgroud)
@delegate中的' @ ' 是否赋予该变量任何特殊的语义含义?
或者这只是我之前没遇到过的惯例?
有没有办法使用关键字作为参数?我想创建一个名为BytesToValue()
的方法,它看起来像这样:
public static T BytesToValue<T>(byte[] buffer, T type)
{
string retType = typeof(T).ToString();
if (retType.Contains(".Byte"))
{
// code here.
}
else if (retType.Contains(".Int16"))
{
// code here.
}
// and so on with all other types.
}
Run Code Online (Sandbox Code Playgroud)
我希望T type
参数只接受一个关键字,例如BytesToValue(new byte[] { 0, 0, 0, 0 }, float)
,有没有办法使用关键字作为参数?我知道这个例子不会工作,但有没有办法使它工作?如果没有那么我该怎么办?