티스토리 뷰

Series

for foreach [C#] List

More Code 2018. 6. 20. 20:27


using System;
using System.Collections.Generic;

namespace Console1
{
class Program
{
static void Main(string[] args)
{
List<string> animals = new List<string>();
animals.Add("cat");
animals.Add("dog");
animals.Add("fox");

foreach (string animal in animals)
{
Console.WriteLine(animal);
}
}
}
}

/* Output
cat
dog
fox
*/



using System;
using System.Collections.Generic;

namespace Console1
{
class Program
{
static void Main(string[] args)
{
List<string> animals = new List<string>() { "cat", "dog", "fox" };

foreach (string animal in animals)
{
Console.WriteLine(animal);
}
}
}
}

/* Output
cat
dog
fox
*/


'Series' 카테고리의 다른 글

for [C/C++] int  (0) 2018.06.21
for [Java] int  (0) 2018.06.20
for foreach [C#] int  (0) 2018.06.20
for [Python] List  (0) 2018.06.20
for [Python] range  (0) 2018.06.20
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함