using System;
class Person
{
// Fields
private string firstName;
private string lastName;
private int age;
// Constructor
public Person(string firstName, string lastName, int age)
{
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
// Properties
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
public int Age
{
get { return age; }
set { age = value; }
}
// Method
public void DisplayDetails()
{
Console.WriteLine($"Name: {firstName} {lastName}, Age: {age}");
}
}
class Program
{
static void Main()
{
// Creating an object of the Person class
Person person1 = new Person("John", "Doe", 30);
// Accessing properties
Console.WriteLine($"First Name: {person1.FirstName}");
Console.WriteLine($"Last Name: {person1.LastName}");
Console.WriteLine($"Age: {person1.Age}");
// Modifying properties
person1.Age = 31;
// Calling a method
person1.DisplayDetails();
}
}