generate functionThu, 22 Dec 2022

define class with two properties name as string age as int build get and set methods. regular build class method and a copy type method

class Person { private string _name; private int _age; public string Name { get { return _name; } set { _name = value; } } public int Age { get { return _age; } set { _age = value; } } public Person() { _name = ""; _age = 0; } public Person(string name, int age) { _name = name; _age = age; } public Person GetCopy() { return new Person(_name, _age); } public override string ToString() { return _name + " " + _age; } } Person p1 = new Person(); p1.Name = "Jo"; p1.Age = 21; Person p2 = new Person("Jo", 21); Person p3 = p1.GetCopy();

Questions about programming?Chat with your personal AI assistant