Sunday, December 1, 2013

How object is created using Type/Class? [ClassName] [ObjectName] = new [ClassName()];

Here is a simple example.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
MyClass myclass1 = new MyClass(); // calls the constror with no parameters
string value = "abc";
MyClass myclass2 = new MyClass(value); // calls the constror with one parameters

}
public class MyClass()
{
public MyClass()
{
//this is the consructor with no paraameters
//it has the same name as the class an no return or void
}
public MyClass(string value)
{
//this is the consructor with one paraameters
//it has the same name as the class an no return or void
}
}

}
}





jdweng


No comments:

Post a Comment