有没有办法使用Tuple类,但提供其中的项目名称?
例如:
public Tuple<int, int, int int> GetOrderRelatedIds()
Run Code Online (Sandbox Code Playgroud)
返回OrderGroupId,OrderTypeId,OrderSubTypeId和OrderRequirementId的id.
让我的方法的用户知道哪个是哪个是很好的.(当你调用方法时,结果是result.Item1,result.Item2,result.Item3,result.Item4.不清楚哪一个是哪个.)
(我知道我可以创建一个类来保存所有这些ID,但是这些ID已经拥有了他们自己的类,并为这个方法的返回值创建一个类看起来很傻.)
我想在C#中做以下事情(来自Python背景):
strVar = "stack"
mystr = "This is %soverflow" % (strVar)
Run Code Online (Sandbox Code Playgroud)
如何用字符串外的值替换字符串中的标记?
如何和"可能"组织从返回元组类型的方法返回与参数的名称,作为一个exapmle
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*/
}
Run Code Online (Sandbox Code Playgroud)
和调用参数 methodTuple.Name不喜欢methodTuple.Item1....N
这可能吗?
UPD:我想用没有新命名类型的命名参数创建对象.