class Employee
{
public Employee()
{
}
}
using System;
namespace ConsoleApplication1
{
class Employee
{
int empID;
string empName;
string empAddress;
//Default Constructor
public Employee()
{
empID = 0;
empName = "N/A";
empAddress = "N/A";
}
//Parameterized constructor.
public Employee(int ID,string name,string address)
{
empID = ID;
empName = name;
empAddress = address;
}
public void showData()
{
Console.WriteLine("Employee ID :="+empID);
Console.WriteLine("Employee Name :="+empName);
Console.WriteLine("Employee Address :="+empAddress);
}
}
class Program
{
static void Main(string[] args)
{
Employee emp = new Employee (1,"RAJ","USA");
emp.showData();
Console.ReadLine();
}
}
}
using System;
namespace ConsoleApplication1
{
class staticConstructor
{
static double price;
static staticConstructor()
{
Console.WriteLine("Static constructor called");
if (price <= 0)
{
price = 10;
}
}
public static void showData()
{
Console.WriteLine("Price = "+price);
}
}
class Program
{
static void Main(string[] args)
{
staticConstructor obj = new staticConstructor();
staticConstructor.showData();
Console.ReadLine();
}
}
}
using System;
namespace ConsoleApplication1
{
public class PrivateConstructor
{
private PrivateConstructor() { }
public static int Count;
public static int ShowCount()
{
return Count++;
}
}
class Program
{
static void Main(string[] args)
{
// If you uncomment the below code, it will give the error.
// You cannot create the object, if private constuctor is there.
// No instance constructor is available.
// PrivateConstructor obj=new PrivateConstructor()
PrivateConstructor.Count = 100;
PrivateConstructor.ShowCount();
Console.WriteLine("New count: {0}", PrivateConstructor.Count);
Console.ReadLine();
}
}
}