Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named tuple type alias #3276

Closed
ydlv opened this issue Mar 18, 2020 · 3 comments
Closed

Named tuple type alias #3276

ydlv opened this issue Mar 18, 2020 · 3 comments

Comments

@ydlv
Copy link

ydlv commented Mar 18, 2020

C# currently supports tuples with specifically-named properties, like defining:

(double x, double y) point = (1,2); // to access - point.x, point.y

Which is great, by the way. It allows creating simple struct-ish types that you can use, for example, for return types or type arguments.

However, a repetitiveness problem may arise: if your function, say, returns an IReadOnlyCollection<(int id, string result)> (sorry for lack of creativity), and you'll want another function to accept that as a parameter, you need to again write IReadOnlyCollection<(int id, string result)>, which gets more frustrating when names get just a bit longer.

What I'm suggesting is that you'd be able to declare a named-tuple like a named type:

public type Point = (int x, int y);

I've seen a suggestion to do that similar to a using directive, similar to how you can already write something like:

using ShortTypeName = SomeGenericType<TArg1, TArg2>;

But what I'm suggesting is something that will have an access modifier and can be part of a namespace or nested in another type, similar to a delegate declaration. That way you can use it outside of the same CS file, unlike an alias of a using directive.

@canton7
Copy link

canton7 commented Mar 18, 2020

Sounds a lot like Records. See #3231, #3226, #3213, #3170, #3146, #3137, #2750, #2699, #2691, #1667, and many more besides.

@ufcpp
Copy link

ufcpp commented Mar 19, 2020

see also #423

@YairHalberstadt
Copy link
Contributor

Closing as duplicate between #410, #259, #423

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants