Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign multiple names simultaneously to a C# class

Is there a way in which a C# class can be given multiple names, eg:

class Foo{}

class AlternativeFooName refers to Foo

I want to be able to access Foo through both names, Foo and AlternativeFooName but without having to inherit from Foo.

An application for this would be giving a class a long descriptive name but being able to abbreviate it when it is used, eg:

instead of Foo f= new Foo(); being able to use the following with the same effect: F f= new F();

like image 672
Eugenio De Hoyos Avatar asked Dec 12 '22 16:12

Eugenio De Hoyos


2 Answers

the using directive applies to classes as well, for example:

using C = System.Console;
like image 169
Jimmy Avatar answered Dec 30 '22 02:12

Jimmy


You can use a using statement, e.g.:

using Foo = My.Namespace.LongFoo;
like image 30
Matthew Abbott Avatar answered Dec 30 '22 02:12

Matthew Abbott