Person : Just a basic Class and calls to Class
public class Person
{
// Field
public string name;
// Constructor that takes no arguments.
public Person()
{
name = "unknown";
}
// Constructor that takes one argument.
public Person(string nm)
{
name = nm;
}
// Method
public void SetName(string newName)
{
name = newName;
}
}
class TestPerson
{
static void Main()
{
// Call the constructor that has no parameters.
Person person1 = new Person();
Console.WriteLine(person1.name);
person1.SetName("John Smith");
Console.WriteLine(person1.name);
// Call the constructor that has one parameter.
Person person2 = new Person("Sarah Jones");
Console.WriteLine(person2.name);
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.Read();
}
}
// Output:
// unknown
// John Smith
// Sarah Jones