Вопрос

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