Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is C# 6.0 #pragma disable warnings feature?

Tags:

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?

like image 208
Stilgar Avatar asked Jul 28 '15 16:07

Stilgar


Video Answer


1 Answers

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

like image 130
Jon Skeet Avatar answered Sep 18 '22 08:09

Jon Skeet