๐ง if ~ else
๐ง switch, case
-์ ์, ๋ฌธ์์์, ๋ฌธ์์ด
- ๋ชจ๋ case์ defaul์๋ break๊ฐ ๋ฐ๋์ ์์ด์ผ ํจ
namespace ConsoleApp4
{
class Myclass
{
static void Main(string[] args)
{
int nNum = 1;
switch(nNum)
{
case 1:
Console.WriteLine("1 ์
๋๋ค.");
break;
case 2:
Console.WriteLine("2 ์
๋๋ค.");
break;
}
string str = "yes";
switch (str)
{
case "yes":
Console.WriteLine("yes ์
๋๋ค.");
break;
case "no":
Console.WriteLine("no ์
๋๋ค.");
break;
}
}
}
}
๐ช ๋ฐ๋ณต๋ฌธ
โถ for
for(; ;) → ๋ฌดํ๋ฐ๋ณต
โถ while, do~while
while(true)
โถforeach
์ฒ์๋ถํฐ ๋๊น์ง ์์ฐจ์ ์ผ๋ก ๊ฐ์ ๋ฐ๋ณตํ์ฌ ์ฝ๋ ์ญํ → ์ฝ๊ธฐ ์ ์ฉ
foreach(๋ฐ์ดํฐํ ๋ณ์ in ๋ฐฐ์ด๋ช (์ปฌ๋ ์ ๋ช ))
{
}
namespace ConsoleApp4
{
class Myclass
{
static void Main(string[] args)
{
int[] Array1 = { 1, 2, 3, 4 };
foreach(int nValue in Array1)
{
Console.WriteLine(nValue);
}
}
}
}
๋ฌด์กฐ๊ฑด ์์ฐจ์ ์ผ๋ก ์ฒ์๋ถํฐ ๋๊น์ง ์ฝ์
foreach๋ ์ฝ๊ธฐ ์ ์ฉ!
foreach๋ฌธ ์์์ nValue๋ ์ฝ๊ธฐ ์ ์ฉ์ด๋ผ
nValue +1; ๊ณผ ๊ฐ์ ๊ณ์ฐ์ ํ๋ค๋ฉด ์๋ฌ ๋จ
namespace ConsoleApp4
{
class Myclass
{
static void Main(string[] args)
{
ArrayList List = new ArrayList();
List.Add(1);
List.Add(2);
List.Add(3);
foreach(int m in List)
{
Console.WriteLine(m);
}
}
}
}
'C#' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C# ๊ธฐ์ด๊ณต๋ถ] ๋ฐฐ์ด(1) ์ผ์ฐจ์๋ฐฐ์ด๊ณผ ๋ค์ฐจ์๋ฐฐ์ด (0) | 2023.01.06 |
---|---|
[C# ๊ธฐ์ด๊ณต๋ถ] ์ ํ๋ฌธ(goto, continue, return, break)/ ์์ธ ์ฒ๋ฆฌ๋ฌธ(if~else)(try~catch)(try~finally)(throw) (0) | 2023.01.06 |
[C# ๊ธฐ์ด๊ณต๋ถ] C# ๊ธฐ๋ณธ ๋ฌธ๋ฒ(์ฐ์ฐ์) (0) | 2023.01.04 |
[C# ๊ธฐ์ด๊ณต๋ถ] ๊ฐ ํ์,์ฐธ์กฐํ์ (0) | 2023.01.04 |
[C# ๊ธฐ์ด๊ณต๋ถ] ๊ตฌ์กฐ์ฒด (0) | 2023.01.04 |