By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,865 Members | 1,453 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,865 IT Pros & Developers. It's quick & easy.

Type alias

P: n/a
Hello, everybody!

I'd like to make global type alias.

If I used c++ I would write the following code to create a global type
alias:
typedef SomeType MyAlias;

I've found that using keyword could be used to make type/namespace aliases.

using MyAlias = SomeTypeOrNamespace;

But such an alias applies only to current module and should be at the top of
it (not allowed inside class definition).

So is there any possibility to make a global type alias in C#?

Thanks in advance.
Apr 11 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi,

No other than that, why you use it s much? Personally I have never used it
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Maxim" <vmu [_at_] mail [ _dot_ ] ru> wrote in message
news:O$**************@TK2MSFTNGP05.phx.gbl...
Hello, everybody!

I'd like to make global type alias.

If I used c++ I would write the following code to create a global type
alias:
typedef SomeType MyAlias;

I've found that using keyword could be used to make type/namespace
aliases.

using MyAlias = SomeTypeOrNamespace;

But such an alias applies only to current module and should be at the top
of
it (not allowed inside class definition).

So is there any possibility to make a global type alias in C#?

Thanks in advance.

Apr 11 '06 #2

P: n/a


Thanks for answering, Ignacio
No other than that, why you use it s much?


I don't. I'm new to C# and .NET and trying to figure out how it works.
I'm implementing WebService client now and proxy classes have very lengthy
names. And code looks confusing. So I decided to use some type aliases to
make it more readable.
Apr 11 '06 #3

P: n/a

"Maxim" <vmu [_at_] mail [ _dot_ ] ru> wrote in message
news:O$**************@TK2MSFTNGP05.phx.gbl...
Hello, everybody!

I'd like to make global type alias.

If I used c++ I would write the following code to create a global type
alias:
typedef SomeType MyAlias;

I've found that using keyword could be used to make type/namespace
aliases.

using MyAlias = SomeTypeOrNamespace;

But such an alias applies only to current module and should be at the top
of
it (not allowed inside class definition).

So is there any possibility to make a global type alias in C#?


No.
I like the above using syntax, though I usually won't do any renaming:

using ClassName = Namespace1.Namespace2.ClassName;

This documents exactly what classes I'm using, and helps anyone who's
reading the code to find ClassName.

Oddly, the equivalent Java syntax

import p1.p2.ClassName;

is standard, and

import p1.p2.*;

is considered lazy, where in C#, class-level using statements are almost
unheard of.
Apr 12 '06 #4

P: n/a
<"Maxim" <vmu [_at_] mail [ _dot_ ] ru>> wrote:
No other than that, why you use it s much?


I don't. I'm new to C# and .NET and trying to figure out how it works.
I'm implementing WebService client now and proxy classes have very lengthy
names. And code looks confusing. So I decided to use some type aliases to
make it more readable.


The thing is, it makes it *less* readable for other people - and to you
in a few months' time. Performing a mental translation from one type
name to another is harder work than just reading the longer name in the
first place, IMO.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 12 '06 #5

P: n/a
Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
The thing is, it makes it *less* readable for other people - and to you
in a few months' time. Performing a mental translation from one type
name to another is harder work than just reading the longer name in the
first place, IMO.


I disagree. When I write

Dictionary<MainQueueIdentifier, StackPointer> queueReference = new
Dictionary<MainQueueIdentifier, StackPointer>();

the verbosity is so much that it gets in the way. The only way I have
to make it shorter is to use aliases (yuck, don't work outside the
current file, aren't used by intellisense) or to define my own class:

class QueueReference : Dictionary<MainQueueIdentifier, StackPointer>
{
... copy all of the constructors
}

This class hasn't helped at all. It's done exactly the same job as a
type-alias-directive would do, but at the cost of twenty extra lines
of code.

--
Lucian
Apr 12 '06 #6

P: n/a
Lucian Wischik wrote:
Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
The thing is, it makes it *less* readable for other people - and to you
in a few months' time. Performing a mental translation from one type
name to another is harder work than just reading the longer name in the
first place, IMO.


I disagree. When I write

Dictionary<MainQueueIdentifier, StackPointer> queueReference = new
Dictionary<MainQueueIdentifier, StackPointer>();

the verbosity is so much that it gets in the way.


I agree that it's somewhat ugly - although as I prefer to use
interfaces where possible, I'd have different types on the left hand
side and the right hand side anyway - but I personally prefer that to
having to look up the meaning of something elsewhere.

I guess it's a personal preference.

Jon

Apr 12 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.