.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> .Net Framework >> Post New Resource Bookmark and Share   

 Subscribe to Articles

The Value Types in .NET Framework

Posted By:Hefin Dsouza       Posted Date: August 26, 2009    Points: 50    Category: .Net Framework    URL: http://www.dotnetspark.com  

The Value Types in .NET Framework. This article can also be used to prepare your self for MCTS 70-536.The article contains the
 

The Value Types in .NET Framework. This article can also be used to prepare your self for MCTS 70-536.The article contains the

Lesson 1 Objectives of theChapter 1 of MOC 2956A : Core Foundations of .NET Framework 2.0



The objectives of this Article is to undertand
* Chosing the most efficent builtin Value Type
* Declaring Value Types
* Creating your own types
- Structures
- Enumerators
Understanding the concepts of Value Types is very simple.
Value Types are variables that directly store the value rather than storing only
the refernce to the value stored somewhere else in the memory.
The Value types are Stored in a Memory Area called stack
The stack is a memory area where the runtime can easily create,read,update and remove value quickly without any performance stress.

All primarily numeric and Boolean values are Value Types.

Some of the Built-In value types are
SByte,Byte,Int16,Int32,UInt32,Int64,Single,Double,Decimal,Boolean,Char,DateTime etc..

There are many more Value Types in the .NET Framework.
Declaring ValueTypes
Declaring of value types are very simple
In C#

// ;
int num;

In VB

//Dim as
Dim num as Integer

Value Type Variables will never hold a Null Value.
If you need a Value Type variable to hold a null Value we use NullableTypes

int? num=null;
//or
Nullable num=new Nullable();

In VB

Dim num as Nullable(Of Integer)=Nothing

Creating User-Defined Value Type
To create a User-Defined Value Type in .NET we need to create a Structure
As a matter of Fact Value Types like int,single,DateTime,Point are all Structures.
To create our own Structure
In C#

struct Rectangle
{
int height;
int width;
}

In VB

Structure Rectangle
Dim height as Integer
Dim width as Integer
End Structure

One more Form of an Value Type is an Enumerator
Enums are used to provide a list of options for developers to use in their Class.
The Following example creates an Enum for PaymentMode
In C#

enum PaymentMode
{
Cash,
Cheque,
CashOnDelivery
}

In VB

Enum PaymentMode as Integer
Cash
Cheque
CashOnDelivery
End Enum

Conclusions


Value Types are those types that store values on the Stack.
DataTypes like int,single,float,DateTime,Point etc are Value Types
Custom Value Types can be created using Structures
List of Options for developers can be made by using Enumerators

Note:If you want any assistance about other MCTS 70-536 contents PM me .

Regards
Hefin Dsouza
 Subscribe to Articles

     

Further Readings:

Responses
Author: J A Chauhan         Company URL: http://www.dotnetspark.com
Posted Date: November 30, 2010

int num?=null;
//or
Nullable num=new Nullable();


there have been some mistake brother
its
int? num = null;
//or
Nullable<num>
//or
Nullable num = new Nullable();
Author: Hefin Dsouza         Company URL: http://www.dotnetspark.com
Posted Date: November 30, 2010

Thanks for the Correction i corrected the code....

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend