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); } }
- wikipedia says .net framework c# 6.0 4.6.
- this question (and visual studio 2015 ctp test) says clr version 4.0.30319.0.
- this msdn page says .net 4, 4.5, 4.5.2 uses clr 4. there isn't information .net 4.6.
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
Post a Comment