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:
In
previous posts I explained cursor in sql server with example, oops concepts in c# with examples, difference between dispose vs finalize method, difference between pageload and page_init in asp.net, constructors in c#, vb.net, delegates in c# with example and many articles
relating to
interview questions, asp.net, c#.net. Now I will explain
difference between instantiation and initialization in c#, vb.net with example.
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. |
|||
|
|||
4 comments :
Nice...
Nice...
Helpful
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..
Note: Only a member of this blog may post a comment.