Did You Know?
You can set class fields with ‘out’ method parameters
Whether you like out parameters or not in C#, they are here to stay. They decorate a number of common patterns in the .NET ecosystem.
- The
TryParsepattern where the return is aboolthat indicates success and your parse result comes from theoutparameter.
However, very often you want to set your class field with the parse result. At first you would assume that you need to declare a temporary variable to hold the value and then assign the field.
|
|
However, this isn’t necessary. Turns out you can just set the field directly.
|
|