KO CSharp Keyword init - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
C#: init
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
๋์ค์ ์์๋ก ๋ณ๊ฒฝํ๋ ๋์ ๊ฐ์ฒด๊ฐ ์ด๊ธฐํ๋ ๋ ์์ฑ์ ํ ๋นํ ์ ์์ต๋๋ค.
๊ฐ๋จํ ์์ (Example.cs)
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
var item = new Item { Name = "Ore" };
System.Console.WriteLine(item.Name);
class Item { public required string Name { get; init; } }
๊ฒฐ๊ณผ:
Ore
ํต์ฌ๋ก
public required string Name { get; init; }
์์ 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)
{
Profile profile = new() { Name = "Archer" };
Console.WriteLine(profile.Name);
}
}
public class Profile { public required string Name { get; init; } }
์ 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)
{
Item item = new() { Code = 12, Label = "Ore" };
Console.WriteLine($"{item.Code}:{item.Label}");
}
}
public class Item { public required int Code { get; init; } public required string Label { get; init; } }
๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.