UNITY版本与C#版本关系 Unity 5.5.4 自带的Mono也可以支持C# 6,在mcs.rsp文件中添加一行:-langversion:6即可。 Unity 2017.1 C# 6.0 试验性地支持新脚本运行时。This includes Mono 4.8 and IL2CPP with support for C# 6 and .NET 4.6 Unity 2018.1 C# 7.2
//元组可以直接由函数返回 var method_1 = Program.MethodTest(); Console.WriteLine(method_1.a + method_1.b); //-----元组的解构------- var testCls = new MyClass{ A = 1,B = 2,C = 3}; var(args1, args2, args3) = testCls; Console.WriteLine($"当前args1:{args1},args2:{args2},args3:{args3}"); //元组解构的优先级默认如果本类中有实现则执行本类内部实现,如果没有则执行外部,如扩展函数 }
static (int a, int b) MethodTest() { var t = (1,2); return t; } }
publicclassMyClass { publicint A { get; set; } publicint B { get; set; } publicint C { get; set; } // public void Deconstruct(out int a,out int b,out int c) // { // a = A; // b = B; // c = C; // } } publicstaticclassExtension4Tuple{ publicstaticvoidDeconstruct(this MyClass cls, outint a, outint b, outint c) { a = 10; b = 11; c = 12; } } }