Topic List | Page List: 1 |
---|---|
Topic | Cool function I wrote |
Sahuagin 10/05/18 11:25:01 AM #22: | checking some of my code, one place I use ref is on string validation
the bool return value indicates whether the string changed, and the string changes to a different string if it was "messy" (whatever that means in the context of the method) Magus 10 posted... Yeah, multiple returns is the scenario I was thinking about with tuples being another option, although I suppose in the case where you're checking an error return value then out params are probably a little easier to use. another scenario is method chaining. if you want to return values while method chaining you have to use out parameters. I have a tree control where I build the parts of the tree in a method chain:
It's maybe a bit overkill, but I just wrote a method that allows me specifically to assign in a method chain, which allows me to avoid a starting variable at the top.
turns this:
to this:
it's not a huge difference, but it reads a lot nicer since the assignment is now where the actual value is instead of at the opposite end also with TryParse, I actually clean it up so that I can write this: if (someText.IsNot<int>(out var intValue)) --- ... Copied to Clipboard! |
Topic List | Page List: 1 |