Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Last active May 17, 2023 08:12
Show Gist options
  • Save Strelok78/4481be581fb8e305e9eb28560540a8d4 to your computer and use it in GitHub Desktop.
Save Strelok78/4481be581fb8e305e9eb28560540a8d4 to your computer and use it in GitHub Desktop.
Gets a data set consisting of a name and a rank.
internal class Program
{
public static void Main()
{
SoldierBaseUI application = new SoldierBaseUI();
application.StartUI();
}
}
class SoldierBaseUI
{
private List<Soldier> _soldiers = new List<Soldier>
{
new Soldier("Soldier 1", "Fully equiped", "Capitan", new DateTime(2010, 5, 20)),
new Soldier("Soldier 2", "Fully equiped", "lieutenant", new DateTime(2020, 6, 14)),
new Soldier("Soldier 3", "Fully equiped", "Capitan", new DateTime(2012, 7, 19)),
new Soldier("Soldier 4", "Fully equiped", "lieutenant", new DateTime(2018, 3, 12)),
new Soldier("Soldier 5", "Fully equiped", "Capitan", new DateTime(2014, 9, 16)),
new Soldier("Soldier 6", "Fully equiped", "lieutenant", new DateTime(2019, 12, 24)),
new Soldier("Soldier 7", "Fully equiped", "lieutenant", new DateTime(2021, 10, 23)),
new Soldier("Soldier 8", "Fully equiped", "General", new DateTime(2000, 11, 21)),
new Soldier("Soldier 9", "Fully equiped", "General", new DateTime(2009, 8, 30)),
new Soldier("Soldier 10", "Fully equiped", "Capitan", new DateTime(2017, 1, 23)),
};
public void StartUI()
{
Console.WriteLine("Soldiers: \nName _ Rank _ ");
var soldierMainInfo = _soldiers.Select(soldier => new { soldier.Name, soldier.Rank }).ToArray();
for(int i = 0; i < soldierMainInfo.Length; i++)
{
Console.WriteLine($"Name: {soldierMainInfo[i].Name}, Rank: {soldierMainInfo[i].Rank}");
}
Environment.Exit(0);
}
}
class Soldier
{
public Soldier(string name, string armament, string rank, DateTime dutyLengthInMonths)
{
Name = name;
Armament = armament;
Rank = rank;
Months = ((DateTime.Now.Year - dutyLengthInMonths.Year) * 12) + DateTime.Now.Month - dutyLengthInMonths.Month;
}
public string Name { get; private set; }
public string Armament { get; private set; }
public string Rank { get; private set; }
public int Months { get; private set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment