C#/수업 내용
List<T> 실습
HSH12345
2023. 1. 10. 15:24
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace Study09
{
class App
{
public App()
{
List<Armor> armors = new List<Armor>();
armors.Add(new Armor("가죽갑옷"));
Console.WriteLine(armors.Count);
Console.WriteLine(armors[0].Name);
armors[0] = new Armor("판금갑옷");
Console.WriteLine(armors[0].Name);
armors.Add(new Armor("천옷"));
Console.WriteLine(armors.Count);
armors.Add(new Armor("가죽갑옷"));
for (int i = 0; i < armors.Count; i++)
{
if(armors[i] != null)
{
Console.WriteLine(armors[i].Name);
}
}
Console.WriteLine();
armors.Remove(armors[0]);
foreach(Armor armor in armors)
{
if (armor != null)
{
Console.WriteLine(armor.Name);
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study09
{
class Armor
{
private string name;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public Armor(string armor)
{
this.Name = armor;
}
}
}