I hope I missed this in the docs. Is there a way to declare a type synonym in C#?
You can use the using statement to create an alias for a type.
For example, the following will create an alias for System.Int32
called MyInt
using MyInt = System.Int32;
Alternatively, you can use inheritance to help in some cases. For example
Create a type People
which is a List<Person>
public class People: List<Person> { }
Not quite an alias, but it does simplify things, especially for more complex types like this
public class SomeStructure : List<Dictionary<string, List<Person>>> { }
And now you can use the type SomeStructure
rather than that fun generic declaration.
For the example you have in your comments, for a Tuple
you could do something like the following.
public class MyTuple : Tuple<int, string> { public MyTuple(int i, string s) : base(i, s) { } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With