4 ms·
Further proof for my personal conviction that C# is a very interesting, progressive language which masquerades as a Java clone. I once copied the style of a ma
by chadzawistowski 14y ago
Further proof for my personal conviction that C# is a very interesting, progressive language which masquerades as a Java clone.
I once copied the style of a maybe monad using LINQ - the WinRT apis lack a "FileExists?" method, so I used LINQ to search a directory's contents for a filename. An IEnumerable of size of zero represented None, and size one represented Some.
Unfortunately, a simple try/catch around an attempt to open the desired file was more efficient and clearer to understand.
- daknok 14y agoYou should use try/catch; branching would imply a race condition in a multithreaded environment (what if another process deletes the file between the check and the use of the file?).
- krallja 14y agoLINQ has an .Empty() extension method, and you should use that instead of .Count()==0 when determining if an expression is empty.