Gabe
Gabe

Reputation:

How do you give a namespace an alias in C#

I have a large namespace: Foo.Bar.Space.Station.Bar and I was to alias is as something shorter like, Station. How do I do that in the using section?

using Foo.Bar.Space.Station.Bar Object ???

so I can do this

Station.Object obj = new ...

instead of

Foo.Bar.Space.Station.Bar.Object obj = new ...

Upvotes: 5

Views: 3736

Answers (3)

ShdNx
ShdNx

Reputation: 3213

using Station = Foo.Bar.Space.Station.Bar;

But in my opinion, having two namespaces named Bar is not a very good idea. :) Even if it's not real code.

Upvotes: 4

MartinHN
MartinHN

Reputation: 19772

using Foo.Bar.Space.Station.Bar = Station;

Upvotes: -4

Jake Pearson
Jake Pearson

Reputation: 27717

You can give an alias to a namespace in a using statement.

using Station = Foo.Bar.Space.Station.Bar;

Upvotes: 19

Related Questions