KO CSharp Keyword foreach - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
C#: foreach
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
์ํ์ค ์์๋ฅผ ๋ฐ๋ณตํฉ๋๋ค. wait foreach๋ ๋น๋๊ธฐ ์ํ์ค๋ฅผ ์ฝ์ต๋๋ค.
๊ฐ๋จํ ์์ (Example.cs)
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
string[] names = ["ore", "wood"];
foreach (string name in names) System.Console.WriteLine(name);
๊ฒฐ๊ณผ:
ore
wood
ํต์ฌ๋ก
foreach (var item in items) { ... }
์์ 1: ๊ธฐ๋ณธ ํํ
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
string[] names = ["ore", "wood"];
foreach (string name in names) Console.WriteLine(name);
}
}
์ 2: ๋ ๋ค๋ฅธ ์ค์ ํ์
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
Dictionary<string, int> counts = new() { ["ore"] = 5, ["wood"] = 3 };
foreach (var (name, count) in counts) Console.WriteLine($"{name}={count}");
}
}
๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.