473,545 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 = SomeTypeOrNames pace;

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 2604
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$******** ******@TK2MSFTN GP05.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 = SomeTypeOrNames pace;

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$******** ******@TK2MSFTN GP05.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 = SomeTypeOrNames pace;

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.Name space2.ClassNam e;

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.co m>
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.co m> 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<Main QueueIdentifier , StackPointer> queueReference = new
Dictionary<Main QueueIdentifier , 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<Main QueueIdentifier , 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.co m> 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<Main QueueIdentifier , StackPointer> queueReference = new
Dictionary<Main QueueIdentifier , 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
4435
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) ({ if(x && *x) { free(*x); *x=NULL; } }) void somefunction() { char *x = malloc(10); int *y = malloc(10);
26
3097
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 code will not be idiomatic C. GCC has an extension to ISO C that permits nested functions:...
2
1259
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 some derived table, B or C. In some cases there is no way for the software to know at import time which derived type the data actually is (that...
669
25599
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 paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990....
7
1738
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 : imports XXXXClsLib.VVDB * and this code of class b gives an error Private Function zzz() As String
59
12203
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 declare a type that is an alias for, say, int. Conceptually, this is what I want to do: public MyIntType = int; // won't compile Anyone knows how...
5
8273
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 RoleProvider. However this only occurs after deployment. On my local machine it works fine. So I created the most basic role provider project I could think...
6
1724
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 *); obj *all_symbols, *top_env, *nil, *tee, *quote,
1
120966
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 that has PostgreSQL 7.4.8 installed (see below). My function: CREATE OR REPLACE FUNCTION generate_menu(varchar(255), char(2), varchar(255), int,...
0
7486
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
0
7676
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7932
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7442
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7776
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6001
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, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5347
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4965
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3456
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.