Generic type aliasing - johanvw's blog

johanvw's blog

This is a blog about .NET and other fun stuff :)

Generic type aliasing

When working with C# Generics, it is sometimes useful to alias a particular combination of specific types.

You can do that through the using statement:

   1:  using lRange = System.Collections.Generic.List<int>;
   2:   
   3:  lRange lrTemp = new lRange();
   4:  lrTemp.Add(1);
   5:  lrTemp.Add(2);
   6:  lblResults.Text = lrTemp[0].ToString();

Note that the scope of aliasing is the scope of the file, so you have to repeat aliasing across the project files in the same way you would with using namespaces.

Posted: Oct 09 2008, 07:53 AM by johanvw | with no comments
Filed under:
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: