有没有办法在未初始化的对象属性上使用out
?
例如:
QuoteDetail q = new QuoteDetail();
Dictionary<int, string> messageDict = SplitMessage(msg);
messageDict.TryGetValue(8, out q.QuoteID); //doesn't work
答案 0 :(得分:6)
不,你将无法做到这一点。只需使用临时变量:
QuoteDetail q = new QuoteDetail();
Dictionary<int, string> messageDict = SplitMessage(msg);
string quoteID;
if (messageDict.TryGetValue(8, out quoteID))
{
q.QuoteID = quoteID;
}
答案 1 :(得分:3)
答案 2 :(得分:0)