Why does ConcurrentDictionary.TryRemove require a second out argument?

后端 未结 4 1733
执笔经年
执笔经年 2020-12-15 15:03

I only want to remove a value.. I don\'t need to use the variable afterwards. Why not include an overload where this second parameter was not required?

Do I really h

4条回答
  •  情深已故
    2020-12-15 15:29

    C#7 added discard syntactic sugar

    So now you can write:

    dictionary.TryRemove(entry.Key, out _); 
    

    Reference

    We allow "discards" as out parameters as well, in the form of a _, to let you ignore out parameters you don’t care about:

    p.GetCoordinates(out var x, out _); // I only care about x

提交回复
热议问题