如何和“可能”组织从返回带有参数名称的元组类型的方法返回, 举个例子
private static Tuple<string, string> methodTuple()
{
return new {Name = "Nick", Age = "Twenty"}; /*exception because need to new Tuple<string, string>(){Item1 = "Nick", Item2 = "Twenty"}o*/
}
和调用参数类似 methodTuple.Name
而不是 methodTuple.Item1....N
这可能吗?
UPD:我想创建具有命名参数但没有新命名类型的对象。
最佳答案
在 C# 7.0 (Visual Studio 2017) 中有一个新选项可以做到这一点:
(string first, string middle, string last) LookupName(long id)
关于c# - 如何命名元组属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27908630/