【发布时间】:2019-01-17 09:45:28
【问题描述】:
我有一个 C# 7.0 元组声明,例如:
(int ID, string name, string secondName, int age) foo = (19,"Harry", "Potter", 8);
每次声明一个新的 var 或者我在函数/方法中使用它时,我都需要重写整个声明。 例如:
private (int ID, string name, string secondName, int age) DoSomething((int ID, string name, string secondName, int age)passedElement) {...
我想将其用作自定义类型并编写如下内容:
private MyType DoSomething(MyType passElement) {...
对于我总是使用的传统元组:
使用 MyType = System.Tuple;
它工作正常,但如果我尝试使用:
使用 MyType = (int ID, string name, string secondName, int age);
intellisense 给我一个错误“预期标识符”,在等号右边的部分下划线。
如果有的话,正确的声明方式是什么?
提前谢谢你。
【问题讨论】:
标签: variables tuples declaration using c#-7.0