KO CSharp Keyword when filter condition - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
C#: when์ ํํฐ ์กฐ๊ฑด์
๋๋ค.
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
catch ์์ธ๋ฅผ ํํฐ๋งํ๊ฑฐ๋ ํจํด ์ผ์น ๋ถ๊ธฐ์ ์กฐ๊ฑด์ ์ถ๊ฐํฉ๋๋ค.
๊ฐ๋จํ ์์ (Example.cs)
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
try { throw new System.Exception("sample"); }
catch (System.Exception error) when (error.Message == "sample")
{
System.Console.WriteLine("Matched");
}
๊ฒฐ๊ณผ:
Matched
ํต์ฌ๋ก
catch (Exception e) when (condition) / case pattern when condition:
์์ 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)
{
try { throw new ArgumentException("sample", "count"); }
catch (ArgumentException error) when (error.ParamName == "count") { Console.WriteLine("Handled count"); }
}
}
์ 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)
{
object value = 20;
switch (value) { case int number when number > 10: Console.WriteLine("Large"); break; case int: Console.WriteLine("Small"); break; }
}
}
๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.