Created
February 24, 2024 19:16
-
-
Save GigaOrts/8cf3a2fe723bfee1279080bc3632bedf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
List<Soldier> soldiers = new List<Soldier>() | |
{ | |
new Soldier(10), | |
new Soldier(0), | |
new Soldier(0) | |
}; | |
Print(soldiers); | |
Console.WriteLine("----------"); | |
RemoveAll(soldiers); | |
Print(soldiers); | |
} | |
private static void RemoveAll(List<Soldier> soldiers) | |
{ | |
for (int i = 0; i < soldiers.Count; i++) | |
{ | |
if (soldiers[i].IsAlive == false) | |
{ | |
soldiers.RemoveAt(i); | |
} | |
} | |
} | |
private static void Print(List<Soldier> soldiers) | |
{ | |
foreach (var item in soldiers) | |
{ | |
Console.WriteLine(item); | |
} | |
} | |
} | |
class Soldier | |
{ | |
private int _health; | |
public Soldier(int health) | |
{ | |
_health = health; | |
} | |
public bool IsAlive => _health > 0; | |
public override string ToString() | |
{ | |
return $"Health: {_health}"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment