5 ms·
I see your point on out parameters, they are ripe for abuse. You can abuse out parameters right now, just with a little more effort. var x, y; p.DoSome
by canadaj 10y ago
I see your point on out parameters, they are ripe for abuse. You can abuse out parameters right now, just with a little more effort.
var x, y;
p.DoSomething(out x, out y);
Where this becomes useful, I think, are places where you can't avoid using an out parameter. Now, you can choose to throw away or use the out parameter without explicitly declaring it.
var isNumber = Int32.TryParse(number, out x);
- louthy 10y agoOption types are the way to go for something like this: public static class Parse { public static Option<int> TryInt(string str) { int value; return Int32.TryParse(str, out value) ? Some(value) : None; } } var x = Parse.Int("123").IfNone(0); var x = Parse.Int("456").Match( Some: x => x * 2, None: () => 0 ); Parse.Int("456").Iter(Console.WriteLine); https://github.com/louthy/language-ext/blob/e6ff382a1752c7de575629f43e4f20257a12d525/LanguageExt.Tests/TryOutTests.cs https://github.com/louthy/language-ext/blob/e6ff382a1752c7de...