19

In Visual Studio 2010, under "Advanced Build Settings" there is the following options for "Language Version":

  • default
  • ISO-1
  • ISO-2
  • C# 3.0

Is there any advantage to compiling as C# 3.0, e.g. benchmark speed or stability?

Contango
  • 76,540
  • 58
  • 260
  • 305

3 Answers3

18

The only time you should mess with this is if you are writing code in, say, VS 2010, but you intend that the code should compile on earlier compilers (VS 2005 or VS 2003). This will limit language features, such as LINQ (only in C# 3), iterator blocks (only in ISO-2 and above), etc.

Even then, it is not robust; there are some features that are pretty awkward to detect, and won't be detected - some forms of generic type inference are impacted by this, so you should still test against an earlier compiler.

Unless you have a reason, use "default". Normally, "default" is selected by, er, default. If it is selecting ISO-1, then you have changed your VS settings at some point.

There is not usually any speed difference associated with this - it is about the langauge that is available; however, I have not checked on some subtle cases, for example does the field-like-event implementation revert to the old-way if an earlier compiler selected.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
8

Leave this on default. This means that you can use all of the C# 3.0 language features.

Press "F1", and it comes up with:

http://msdn.microsoft.com/en-us/library/f4ckecs0(v=vs.110).aspx

  • default The compiler accepts all valid language syntax.
  • ISO-1 The compiler accepts only syntax that is included in the ISO/IEC 23270:2003 C# language specification.
  • ISO-2 The compiler accepts only syntax that is included in the ISO/IEC 23270:2006 C# language specification. This specification is available on the ISO Web site.
  • C# 3 The compiler accepts only syntax that is included in the version 3.0 C# Language Specification.
Contango
  • 76,540
  • 58
  • 260
  • 305
  • 2
    I'd suggest adding that ISO-1 corresponds to the version of C# used in the .net 1.0/1.1 framework, and ISO-2 to the version in the 2.0 framework. Newer language versions haven't been submitted to ISO. C# 3 is listed as framework versions 2.0, 3.0, and 3.5 in Wikipedia. Defaul corresponds to the 4.0 frameowrk. – Dan Is Fiddling By Firelight Feb 07 '12 at 14:04
1

To answer the point about advantages: There should be no performance benefits as such in choosing one over the other. What you gain or loose is language features. E.g. C#3 has "var", Object initializers, automatic properties, extension methods, lambda expressions etc etc.

If you want your code to build in a non C#3 environment, such as older .Net or Mono versions of .Net CF then you will need to avoid these. It is possible to write code without these features in C#3 of course, so ISO C# will work in C#3 (and greater).

I have heard people argue that things like LINQ could be inefficient in some cases, so you could argue that well written ISO C# might be more performant. I'm not sure I really agree with this as a blanket statement, if you have perf issues then you need to profile your code and fix the hotspots; avoiding LINQ (for example) is no guarantee of more performant code.

Steve
  • 8,469
  • 1
  • 26
  • 37