C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Default values and Basic conversions of data types in C#


Posted Date: 29 Jun 2007    Resource Type: Articles    Category: .NET Framework
Author: dayaMember Level: Gold    
Rating: 1 out of 5Points: 10



Default values

In general there are two types of variables

1. Class variables &
2. Local variables

Class variables are the variables declared in the class scope Whereas Local variables are the variables declared locally within particular function.
Local variables should be initialized before using it otherwise it will through a compilation error, but class variables are differ even without initializing also we can use it because by default default_values will be added.

Following are the default values assigned to the class variables

Bool - false; Char - \u0000; Sbyte - 0; byte - 0; short - 0; ushort - 0; int - 0;
uint - 0; long - 0; ulong - 0; float - 0.0f; double - 0.0d; decimal - 0.0m; Sbyte - 0 ;Sbyte - 0 Sbyte - 0


Basic conversion

A basic method for implicit conversion is destination should be big enough to hold the value means size of the destination type should be bigger than the source type so that there is no loss of data.

Legal implicit conversion for C# types

Sbyte --> short, int, long, float, double, decimal
byte --> short, ushort, int, uint, long, ulong, float, double, decimal
int --> long, float, double, decimal
float --> double
double & decimal --> None

If the distination size is smaller than the size of the source type then we need to explicitly mention cast of the type, In this case probability of loss of data is high this is known as explicit conversion

Eg:
Double maxWgt = 53.71;
Float minWgt = (float) maxWgt;

---------------------------------------------------------------------




Responses


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

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add 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: Confidence development through Ado.net
Previous Resource: Dotnet mobile a user understanding concept
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use