NamedValueTuple and params keyword #7703
Replies: 3 comments 12 replies
-
What use case does this have? Given you'd have very limited ways of interacting with those tuples within the method, it would seem that you can't avoid allocations and a lot of overhead simply navigating the values. |
Beta Was this translation helpful? Give feedback.
-
It's possible that with params collections you'll end up with a syntax that would work very similarly to this. GIven collection expressions are also exploring dictionary expressions, that would potentially give you the named version also. |
Beta Was this translation helpful? Give feedback.
-
Many thanks for all the feedback. On reflection I think I should have perhaps presented this slightly differently as follows: Currently we have a construct like params object[] args
Later versions of .net support a Span type construct that would be great for all the above issues where the type T is the same for all items in the params as it avoids any need to box or put items on the heap. However this doesn't support the flexibility of the original object array return type, in that it requires all parameters to be of the same type. That's less of a problem if class/reference type objects as we simply specify object or some base class/interface. But it is a problem for value-types because they don't have a common type except object, which has the issues mentioned above. Ideally it would be nice to be able to have something like a Span<*> which would support any type of argument with-out boxing etc. However there is no easy way to produce such a type from practical viewpoint, and adding such a thing to the language would almost certainly be prohibitively expensive. However from a practical point of view we do already have a pre-existing ValueTuple type construct that already exists in the language and uses generics to support holding a set of values of any type. This gives (very nearly) all the functionality we are after and avoids boxing. If you were to imagine the ValueTuple type that supported a method that returned an IEnumerable or better still a Span then you could imagine you could have a method a bit like: Now there are a couple of details about the above that I did skip-over/simplify in the above:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I find ValueTuple a great way to pass lists of values to a function without them being boxed eg:
Beta Was this translation helpful? Give feedback.
All reactions