using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TestApplication
{
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public Person(string name, int age)
{
Name = name;
Age = age;
}
public virtual string GetDescription()
{
return $"Person: {Name}, Age: {Age}";
}
}
public interface IEmployee
{
decimal Salary { get; set; }
void Work();
}
public class Employee : Person, IEmployee
{
public decimal Salary { get; set; }
public string Department { get; set; }
public Employee(string name, int age, decimal salary, string department)
: base(name, age)
{
Salary = salary;
Department = department;
}
public override string GetDescription()
{
return $"Employee: {Name}, Age: {Age}, Salary: {Salary:C}, Department: {Department}";
}
public void Work()
{
Console.WriteLine($"{Name} is working in {Department}");
}
}
public class Repository<T> where T : class
{
private List<T> items = new List<T>();
public void Add(T item)
{
items.Add(item);
}
public T Get(int index)
{
return items[index];
}
public IEnumerable<T> GetAll()
{
return items;
}
}
public enum Status
{
Active,
Inactive,
Pending
}
public static class StringExtensions
{
public static bool IsNullOrEmpty(this string value)
{
return string.IsNullOrEmpty(value);
}
}
public static async Task<string> GetDataAsync()
{
await Task.Delay(1000);
return "Data retrieved";
}
class Program
{
static async Task Main(string[] args)
{
var person = new Person("Alice", 30);
var employee = new Employee("Bob", 35, 50000m, "IT");
var numbers = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var evenNumbers = numbers.Where(n => n % 2 == 0).ToList();
var status = GetStatus(employee);
Console.WriteLine($"Status: {status}");
var testString = "";
if (testString.IsNullOrEmpty())
{
Console.WriteLine("String is empty");
}
var data = await GetDataAsync();
Console.WriteLine(data);
}
static string GetStatus(Person person) => person switch
{
Employee e when e.Salary > 40000 => "High-paid employee",
Employee e => "Regular employee",
Person p when p.Age > 65 => "Senior person",
_ => "Regular person"
};
}
}