C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




What is the difference between string and System.String?


Posted Date: 19 Apr 2005    Resource Type: Articles    Category: .NET Framework

Posted By: Tony John       Member Level: Gold
Rating:     Points: 10



Ever wondered what is the difference between string and System.String (or, int and System.Int32) ? They are just the same and you can use either of them in your C# programs.

C# defines a set of aliases for the types in CLR, which can be treated as data types. For example, System.String is a type (class) in .NET Framework and string is an alias defined (shortcut) for this .NET class. Similary, System.Int32 is a .NET class and int is an alias defined in C# representing the System.Int32 class.

Which one to use ? CLR types or aliases ?

There is no performance reasons to choose or avoid either of them. Since C# aliases represent the same CLR class, they provide the same performace. So, it is upto you to decide which one to use. It would be a good idea to stick to a uniform pattern - either use the C# aliases or CLR types throughout your project (do not mix both) just to have an elegant looking code!

If you think you would ever manually convert your C# code to VB.NET, or if your code may be reviewed by a VB.NET guy, it would be easier if you use the CLR types (because CLR types are common for all .NET languages).

Here is some of the aliases defined in C#:


Alias CLR type

string System.String
char System.Char
bool System.Boolean
sbyte System.SByte
byte System.Byte
short System.Int16
ushort System.UInt16
int System.Int32
uint System.UInt32
long System.Int64
ulong System.UInt64
decimal System.Decimal
float System.Single
double System.Double
void System.Void



Defining custom aliases



You can define your own custom aliases in C# using the syntax shown below:

using verylong = System.Int64;
using forms = System.Windows.Forms;



In the above code, we have defined two aliases. 'verylong' is an alias for the type 'System.Int64' and 'forms' is an alias for the namespace 'System.Windows.Forms'.

The alias 'verylong' can be used just like you use the class System.Int64:

verylong count = 100000;

The alias 'forms' also can be used the same way:

forms.MessageBox.Show(...)

is same as

System.Windows.Forms.MessageBox.Show(...)




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Subscribing and un subscribing event handlers
Previous Resource: How to find out if the computer is connected to Internet ?
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use