What is C# 6.0 #pragma disable warnings feature?

时间:2015-07-28 16:51:21

标签: c#

The list of C# 6.0 final features contains a feature called #pragma listed as "Added" and the example is to disable warnings. However this feature did exist in C# before 6.0. What exactly was added in 6.0?

1 个答案:

答案 0 :(得分:16)

Previously, you had to specify the warning number. So to disable CS0501, you'd use

#pragma warning disable 0501

Now, you can use

#pragma warning disable CS0501

... which is incredibly important when you've got Roslyn Code Analyzers raising warnings with different identifiers. It's basically changed the namespace of warnings from "digits" to "alphanumeric strings".

I don't know the details of the new grammar - I haven't seen a C# 6 spec yet - but the old grammar was:

warning-list:
  decimal-digits
 warning-list whitespaceopt , whitespaceopt decimal-digits