473,403 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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 2595
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: David Ford | last post by:
I have a macro that I use across the board for freeing ram. I'd like to clean up my code so I don't get these warnings. #define sfree(x) _internal_sfree((void **)&x) #define _internal_sfree(x)...
26
by: Adam Warner | last post by:
Hello all, I'm very new to C but I have a number of years of Common Lisp programming experience. I'm trying to figure out ways of translating higher order concepts such as closures into C. The...
2
by: Scott Ribe | last post by:
Here's my issue: Data comes in and is inserted into the database automatically, into a base table A. Later a human looks at the records, fills in some data, and now the records are assigned to...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
7
by: chaz | last post by:
Hi, * this class is defined in assembly XXXXClsLib : Public class VVDB : inherits DBFuncs ... * Assembly YYYYFwApi has a reference to XXXXClsLib * this class B in YYYYFwApi has an imports stmt...
59
by: peter.tornqvist | last post by:
Maybe I'm stupid or maybe I am missing the obvious, but I can't find a way to define a type alias in C# for primitive types (class and interfaces I can inherit from, no problem). I.e I want to...
5
by: Alias | last post by:
Hi - I'm trying to implement a custom RoleProvider based on the SqlRoleProvider. I keep receiving a an error that it can't load type 'MyRoleTest.MyRoleProvider' when trying to load my...
6
by: dillogimp | last post by:
hi This code is taken from a lisp interpreter by Andru Luvisi. typedef struct obj { enum otype type; struct obj *p; // array of pointer, sizeof(obj)=8 } obj; typedef obj * (*primop)(obj *);...
1
by: Slapo | last post by:
Hello everyone, I could use some help with this function I've created (see below) that runs flawlessly on PostgreSQL 8.3.6 on my development machine but ends with an error on the production server...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.