How to assign multiple names simultaneously to a C

2019-07-03 02:33发布

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();

2条回答
Lonely孤独者°
2楼-- · 2019-07-03 02:38

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

using Foo = My.Namespace.LongFoo;
查看更多
SAY GOODBYE
3楼-- · 2019-07-03 02:39

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

using C = System.Console;
查看更多
登录 后发表回答