List를 반복하고 각 항목을 가져 오는 방법은 무엇입니까?
출력이 다음과 같이 보이기를 원합니다.
Console.WriteLine("amount is {0}, and type is {1}", myMoney.amount, myMoney.type);
내 코드는 다음과 같습니다.
static void Main(string[] args)
{
List<Money> myMoney = new List<Money>
{
new Money{amount = 10, type = "US"},
new Money{amount = 20, type = "US"}
};
}
class Money
{
public int amount { get; set; }
public string type { get; set; }
}
foreach는 개체를 복제하지 않습니다.