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

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;


//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;
Nullable num=new Nullable();


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;


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


Enum PaymentMode as Integer
End Enum


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 .

Hefin Dsouza
 Subscribe to Articles


Further Readings:

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

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

there have been some mistake brother
int? num = null;
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