Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

C# - Difference between Initialization and Instantiation

May 18, 2016
Introduction:

Here I will explain difference between initialization and instantiation in c#, vb.net with example or instantiation vs initialization in asp.net or how to instantiate and initialize a class in asp.net using c#, vb.net with example. In c# or vb.net instantiation means declaring object for class and initialization means assigning values to variables or setting initial values.

Description:


Initialization

Initialization means assigning initial value to variables while declaring.

Example of Initialization

Following is the simple example of initialization in application.


  int a;//Declaration

  a = 10;//Initialization

  or

  int a = 10;

Instantiation

Instantiation means defining or creating new object for class to access all properties like methods, operators, fields, etc. from class.

Example

Following is the example of defining instantiation in application.


class sampleclass {
// your code
}
class Program
{
static void Main()
{
// Instantiating sampleclass
sampleclass sobj = new sampleclass();
}
}

If you observe above syntax we created new object by instantiating sampleclass class. By using new object sobj we can access all the methods and properties from sampleclass class.

I hope it helps you to understand difference between initialization and instantiation.

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

4 comments :

SARAVANAN SOMASUNDARAM said...

Nice...

SARAVANAN SOMASUNDARAM said...

Nice...

Naveen Baghel said...

Helpful

nwaf AH said...

Hi. Mr:Suresh Dasari.

Good job. but in the second example if i do like :
{
sampleclass sobj; // Is this Declaration
sobj = new sampleclass(); //and this Instantiating or Initialization
}

thank you..

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.