Replies: 8 comments
-
Are there any really useful use cases? I could see some, but not large benefits in most queries, etc. |
Beta Was this translation helpful? Give feedback.
-
What is the advantage over tuples? E.g.: var myPerson = (FirstName:"John", LastName:"Smith");
var lazy = new Lazy<(string FirstName, string LastName)>(() => ("John", "Smith"));
var myQueue = new Queue<(string FirstName, string LastName)>(); myQueue.Enqueue(myPerson);
var myDictionary = new Dictionary<string, (string FirstName, string LastName)> {
{ "person1", ("John", "Smith") }
}; |
Beta Was this translation helpful? Give feedback.
-
Well, the main advantage the alias - you don't have to specify the structure of the ValueTuple with all types and property names every single time:
Also I don't think people will stop using anonymous types after ValueTuples showed up, especially when you need to add dependency to additional package in order to get it available. Type aliasing can be compatible not only with Anonymous type but with any other type besides and including value tuples. |
Beta Was this translation helpful? Give feedback.
-
The "we might get it one day" feature of records would cover that: class TPerson(string FirstName, string LastName);
... |
Beta Was this translation helpful? Give feedback.
-
Do I understand correctly that you implied to do this:
?
|
Beta Was this translation helpful? Give feedback.
-
Another lightweight variant of syntax using * for local named (they already can't be called 'anonymous') classes:
And one more possible syntax: |
Beta Was this translation helpful? Give feedback.
-
@andrey-messi |
Beta Was this translation helpful? Give feedback.
-
I'd like just generics to accept var myPerson = new {FirstName:"John", LastName:"Smith"};
var lazyNewAlias = new Lazy<myPerson.GetType()>(()=> new {FirstName:"John", LastName:"Smith"} ); and finally inference for constructors: var lazyNewAlias = new Lazy(()=> new {FirstName:"John", LastName:"Smith"} ); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Local Type Alias for anonymous types would be nice solution for dealing with Generics:
This issue came from #427. This current proposal could be alternative solution for #427
Beta Was this translation helpful? Give feedback.
All reactions