【发布时间】:2009-02-09 19:20:04
【问题描述】:
我不确定何时应该在 C# 中使用 匿名类型 而不是 局部变量。
我有:
string fullMessage // This is the full message including sender and recipient names
string sender = GetMessagePart(fullMessage, "from");
string recipient = GetMessagePart(fullMessage, "to");
//do some stuff and deliver the message
我应该使用:
var msg = new {
sender = GetMessagePart(fullMessage, "from")
recipient = GetMessagePart(fullMessage, "to")
};
相反?
【问题讨论】: