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
TryParse
pattern where the return is abool
that indicates success and your parse result comes from theout
parameter.
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.
|
|