It would be interesting to know why the author needs this in F # (a simple example of the intended use would be sufficient).
But I assume that one of the common cases when you can use an uninitialized variable in C # is when you call a function with the out parameter:
TResult Foo<TKey, TResult>(IDictionary<TKey, TResult> dictionary, TKey key) { TResult value; if (dictionary.TryGetValue(key, out value)) { return value; } else { throw new ApplicationException("Not found"); } }
Fortunately, in F # you can handle this situation using much better syntax:
let foo (dict : IDictionary<_,_>) key = match dict.TryGetValue(key) with | (true, value) -> value | (false, _) -> raise <| ApplicationException("Not Found")
Ed'ka
source share