不返回代码标记属性? (__attribute __((noreturn)))

时间:2013-01-26 22:17:32

标签: c# attributes

什么相当于C#中的GCC __attribute__ ((noreturn))归属?禁止在错误执行流的方法中没有return语句的警告。我的代码将通过调用错误thrower函数抛出错误。我在Unity3D 4.0中使用Mono。

1 个答案:

答案 0 :(得分:0)

C#很聪明。如果您有一个返回值的方法,但是throw异常,那么它不会生成警告。

int foo(int bar)
{
    if (bar > 0) return bar + 1;
    throw new NotSupportedException(); 
}

不会产生任何警告。

但是,如果确实生成了警告,则可以使用#pragma warning。见http://msdn.microsoft.com/en-us/library/441722ys(v=vs.80).aspx