再加上Tuple个班.NET4,我一直在努力决定在我的设计中使用它们是否是一个糟糕的 Select .在我看来,Tuple可以作为编写结果类的捷径(我相信还有其他用途).
因此:
public class ResultType
{
public string StringValue { get; set; }
public int IntValue { get; set; }
}
public ResultType GetAClassedValue()
{
//..Do Some Stuff
ResultType result = new ResultType { StringValue = "A String", IntValue = 2 };
return result;
}
相当于:
public Tuple<string, int> GetATupledValue()
{
//...Do Some stuff
Tuple<string, int> result = new Tuple<string, int>("A String", 2);
return result;
}
所以,撇开我忽略元组的可能性不谈,Tuple的例子是一个糟糕的设计 Select 吗?在我看来,它似乎没有那么杂乱,但没有那么self 记录和干净.也就是说,对于ResultType
类型,后面很清楚类的每个部分的含义,但是您需要维护额外的代码.对于Tuple<string, int>
,您需要查找并弄清楚每个Item
代表什么,但编写和维护的代码更少.
您在这一 Select 上的任何经验都将不胜感激.