我不确定在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")
};
改为?