C# Program-2.
C#
Program-2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace constructor
{
class Program
{
static void Main(string[] args)
{
string a = "", b = "";
Console.WriteLine("enter name");
student s = new student(a, b);
a = s.Name = Console.ReadLine();
b = s.Add = Console.ReadLine();
Console.WriteLine("nmae={0} address={1}", a, b);
Console.ReadLine();
}
}
class student
{
private string name;//private variable start from small letter.
private string add;
public string Name//public variable start from capital letter.and we define a private member publicaly to set his properties.
{
get { return name; }
set { }
}
public string Add
{
get { return add; }
set { }
}
public student()
{ }
public student(string name):this()//here this tag is used for chaining of constructor.
{
this.name = name;//here this tag is used to fix that the transfer o value. because here parameter and varibal of same name
//i.e. name and add.
}
public student(string name, string add):this(name)
{
this.name = name;
this.add = add;
}
}
}
0 comments