문제

Is there a way to use out on uninitialized object properties?

Ex:

QuoteDetail q = new QuoteDetail();

Dictionary<int, string> messageDict = SplitMessage(msg);

messageDict.TryGetValue(8, out q.QuoteID); //doesn't work
도움이 되었습니까?

해결책

No, you won't be able to do that. Just use a temporary variable instead:

QuoteDetail q = new QuoteDetail();

Dictionary<int, string> messageDict = SplitMessage(msg);
string quoteID;
if (messageDict.TryGetValue(8, out quoteID))
{
    q.QuoteID = quoteID;
}

다른 팁

Simple answer: NO

You can't use properties. You will have to use a variable instead

BTW: has been answered a dozen times already: Passing a property as an 'out' parameter in C#

You have to initiate the out parameter.

The following link from msdn should help...

http://msdn.microsoft.com/en-us/library/ee332485.aspx

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top