2

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
p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
Ethan
  • 85
  • 1
  • 8

3 Answers3

6

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;
}
p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
3

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#

Community
  • 1
  • 1
Ole Albers
  • 8,715
  • 10
  • 73
  • 166
0

You have to initiate the out parameter.

The following link from msdn should help...

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

gpmurthy
  • 2,397
  • 19
  • 21