Consider options for supporting anonymous structs. #2093
Replies: 3 comments
-
Tuples? |
Beta Was this translation helpful? Give feedback.
-
I rarely use anonymous types now we have tuples. They have pretty much all of the advantages, less overhead, and can be used as return types, type arguments etc. |
Beta Was this translation helpful? Give feedback.
-
I support this as I partially proposed something similar in #2047 though via this proposal by using the (readonly, ref) struct keywords... Today though, I believe one can already use/contrive a local function to produce a mutable struct which facilitates this feature already where as a lamba produces a class... IMHO the problem thus would be describing mutability of fields... not trying to specify if I want a class or structure although I agree the ability to be as specific as possible suits C# well. I question the benefit of either feature proposal though because they only offer syntactic sugar and likely worse performance than if one would simply use a Span with the desired length and extension methods over it to allow access of the fields via those methods as if it were a typed structure.... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In (for example LINQ) numerous scenarios we can create anonymous types with new. However these types are always classes. Could support for creating anonymous structs be added?
Beta Was this translation helpful? Give feedback.
All reactions