相关疑难解决方法(0)

代表的@前缀是否有任何特殊含义?

我曾多次看到ReSharper生成的代码如下所示:

delegate void myHandler(int i);
myHandler myHandlerContainer;
...
foreach (Delegate @delegate in myHandlerContainer.GetInvocationList())
{...}
Run Code Online (Sandbox Code Playgroud)

@delegate中的' @ ' 是否赋予该变量任何特殊的语义含义? 或者这只是我之前没遇到过的惯例?

c# syntax delegates

10
推荐指数
2
解决办法
843
查看次数

你能用关键字作为参数吗?

有没有办法使用关键字作为参数?我想创建一个名为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),有没有办法使用关键字作为参数?我知道这个例子不会工作,但有没有办法使它工作?如果没有那么我该怎么办?

c#

-1
推荐指数
1
解决办法
58
查看次数

标签 统计

c# ×2

delegates ×1

syntax ×1