Write a code snippet to show parameterized constructor?

Tripati_tutu
Posted by Tripati_tutu under C# category on | Points: 40 | Views : 2855
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ParameterizedConst
{
class Program
{
int Eno;
string Ename;
int Esal;
public Program(int Eno1, string Ename1, int Esal1) // parameterized constructor
{
// Here Eno1, Ename1, Esal1 are called as local variables.
Eno = Eno1;
Ename = Ename1;
Esal = Esal1;
}
static void Main(string[] args)
{
Program obj1 = new Program(101, "ravi", 7800);
Console.WriteLine(obj1.Eno + " " + obj1.Ename + " " + obj1.Esal);
Program obj2 = new Program(102, "sham", 12000);
Console.WriteLine(obj2.Eno + " " + obj2.Ename + " " + obj2.Esal);
Console.ReadKey();
}
}
}


In this type of constructors, you can assign different values for different objects according to your requirement.

Comments or Responses

Login to post response