Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using out parameter on class property [duplicate]

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
like image 269
Ethan Avatar asked Mar 20 '26 02:03

Ethan


1 Answers

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;
}
like image 61
p.s.w.g Avatar answered Mar 21 '26 16:03

p.s.w.g



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!