Declaring 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)
  {
  }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)