如何将多个名称同时分配给C#类 [英] How to assign multiple names simultaneously to a C# class

查看:144
本文介绍了如何将多个名称同时分配给C#类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以为一个C#类提供多个名称,例如:

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

class Foo {}

class Foo{}

class AlternativeFooName是指Foo

class AlternativeFooName refers to Foo

我想能够通过Foo和AlternativeFooName两个名称访问Foo,但是不必继承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:

而不是
Foo f = new Foo();
能够使用以下效果相同的效果:
F f = new F();

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

推荐答案

p> use指令也适用于类,例如:

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

using C = System.Console;

这篇关于如何将多个名称同时分配给C#类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆