469,658 Members | 1,862 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,658 developers. It's quick & easy.

Type alias

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
6 2468
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


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

"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
<"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
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
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.

Similar topics

16 posts views Thread by David Ford | last post: by
26 posts views Thread by Adam Warner | last post: by
2 posts views Thread by Scott Ribe | last post: by
669 posts views Thread by Xah Lee | last post: by
7 posts views Thread by chaz | last post: by
59 posts views Thread by peter.tornqvist | last post: by
6 posts views Thread by dillogimp | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.