-
When using private readonly Dictionary<int, T> _myDict = new() { ... };
public static ref T Get(int i)
{
return ref CollectionsMarshal.GetValueRefOrAddDefault(_myDict, i, out _); //Compiler error.
} Ideally there should be an overload without the private static bool _neverUsed;
public static ref T Get(int i)
{
return ref CollectionsMarshal.GetValueRefOrAddDefault(_myDict, i, out _neverUsed); //ok
} Since I think this is a language feature, can we have an attribute added to methods like this to indicate they don't pass the ref parameter to the returned ref and allow such methods to be called with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
https://github.com/dotnet/csharplang/blob/main/proposals/low-level-struct-improvements.md See the parts about NB: In the future, it would help if you included the compiler error, rather than just saying "Compiler error". I had no idea what error it was and had to go create an example so I could see what you were talking about. |
Beta Was this translation helpful? Give feedback.
https://github.com/dotnet/csharplang/blob/main/proposals/low-level-struct-improvements.md
See the parts about
DoesNotEscape
.NB: In the future, it would help if you included the compiler error, rather than just saying "Compiler error". I had no idea what error it was and had to go create an example so I could see what you were talking about.