Does C# 6.0 work for .NET 4.0? -


i created sample project, c#6.0 goodies - null propagation , properties initialization example, set target version .net 4.0 , it... works.

public class cat {     public int taillength { get; set; } = 4;      public cat friend { get; set; }      public string mew() { return "mew!"; } }  class program {     static void main(string[] args)     {         var cat = new cat {friend = new cat()};         console.writeline(cat?.friend.mew());         console.writeline(cat?.friend?.friend?.mew() ?? "null");         console.writeline(cat?.friend?.friend?.taillength ?? 0);     } } 

does mean can use c# 6.0 features software targets .net 4.0? there limitations or drawbacks?

yes (mostly). c# 6.0 requires new roslyn compiler, new compiler can compile targeting older framework versions. that's limited new features don't require support framework.

for example, while can use string interpolation feature in c# 6.0 earlier versions of .net (as results in call string.format):

int = 3; string s = $"{i}"; 

you need .net 4.6 use iformattable new framework version adds system.formattablestring:

int = 3; iformattable s = $"{i}"; 

the cases mentioned don't need types framework work. compiler capable of supporting these features old framework versions.


Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -