Classe:
public class Employee
{
public string Name { get; set; }
public string Position { get; set; }
public Employee(string name, string position)
{
Name = name;
Position = position;
}
public void Promote(string newPosition)
{
if (newPosition == Position)
{
Console.WriteLine("Error: The new position must be different from the current position.\n");
}
else
{
Position = newPosition;
Console.WriteLine("Promotion successfully completed!\n");
}
}
}
Instância:
Employee employee = new Employee("Carlos Pereira", "Administrative Assistant");
Console.WriteLine($"Employee: {employee.Name}");
Console.WriteLine($"Current Position: {employee.Position}");
Console.WriteLine("");
employee.Promote("Administrative Assistant");
employee.Promote("Project Analyst");
Console.WriteLine("--- After promotion ---");
Console.WriteLine($"Employee: {employee.Name}");
Console.WriteLine($"Current Position: {employee.Position}");
Console.WriteLine("");