Class Constructor Example C#

Class Constructor Example C#

class constructor example C#

Class Constructor Example C#

class Person
{
private int age;
private string name;
public Person(string pn)
{
name = pn;
}

public string printName()
{
return name;
}
}
static void Main(string[] args)
{
Person b= new Person(“Manish”);
Console.WriteLine(b.printName());
}

Output – Manish

 

Social Share

Leave a Reply

Your email address will not be published. Required fields are marked *