Click here to Skip to main content
13,193,600 members (55,830 online)
Click here to Skip to main content
Add your own
alternative version


10 bookmarked
Posted 30 Oct 2008

Using Data Type Alias in .Net

, 30 Oct 2008
Rate this:
Please Sign up or sign in to vote.
Data type aliasing allows us to use an alias of a data type instead of actual data type name


Data type aliasing allows us to use an alias of a data type instead of actual data type name.

For example if we want to use System.Int32 in our code but we may want to change it to Int64 or Int16 in future. So instead of using Int32 in our code and then replacing the whole code with Int64 later, what we can do is, we can declare an alias for Int32 and use it, later on when we want to use Int64 we can just change the alias declaration and its done.

Using in code

using MyType = System.Int32; //define alias MyType for System.Int32

//Now we can use the alias MyType anywhere in our code instead of actual System.In32 like below
MyType myNumber=12; 
//If we want to change to System.Int64, We will simply change the alias, that’s it.
using MyType = System.Int64; 
'To declare alias in
Imports MyType=System.Int32 'defines alias for System.Int32

Points of Interest

This is really cool to use when another team is working on some class who’s' final name we don't know, so for the time we can create a dummy class and use an alias throughout the code and later we can replace the alias declaration with actual class name.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

I started programming for fun when I was in Higher Secondary (1995). It was a table writing program in C..haah!! those were the best days of my life Smile | :)

But now it has brought me to no. of jobs in roles of developer, Lead, Architect, Coach and Consultant....

.Net c# is my passion specially when it comes to build api and frameworks to facilitates development teams....

I always learned things by example, now its a pleasure and responsiblity to give learnings back to next generation of coders.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
Trif_cz9-Oct-12 0:52
memberTrif_cz9-Oct-12 0:52 
GeneralOnly class scope and not a .NET feature Pin
mot25630-Oct-08 22:30
membermot25630-Oct-08 22:30 
A type-alias is a syntax used only as part of C# (maybe VB.NET also, I do not know), but it is not a .NET feature. When the code is compiled it is compiled with all the type-aliases replaced with the original type. You can prove this by looking at the IL.

It is still a nice feature though. It would however be much better if you could declare the type-aliases at project scope and not only at class scope.
GeneralRe: Only class scope and not a .NET feature Pin
kobi systems30-Oct-08 23:33
memberkobi systems30-Oct-08 23:33 
GeneralRe: Only class scope and not a .NET feature Pin
PIEBALDconsult31-Oct-08 9:50
memberPIEBALDconsult31-Oct-08 9:50 
GeneralRe: Only class scope and not a .NET feature Pin
kobi systems1-Nov-08 3:33
memberkobi systems1-Nov-08 3:33 
GeneralRe: Only class scope and not a .NET feature Pin
PIEBALDconsult1-Nov-08 4:25
memberPIEBALDconsult1-Nov-08 4:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171018.2 | Last Updated 31 Oct 2008
Article Copyright 2008 by Bhupindra Singh
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid