KO CSharp Keyword scoped - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
๋ฒ์๋ ์ฐธ์กฐ ๋๋ ์ฐธ์กฐ ์ ์ฌ ๋งค๊ฐ๋ณ์ ๊ฐ์ ์ ํจํ ์๋ช ์ ์ ํํฉ๋๋ค. ์ปดํ์ผ๋ฌ๋ ์ค์ ๋ ์๋ช ์ ์ด๊ณผํ๋ ๋ฐฉ์์ผ๋ก ์ด๋ฌํ ์ฐธ์กฐ๊ฐ ๋ฐํ๋๋ ๊ฒ์ ํ์ฉํ์ง ์์ต๋๋ค. ์์ ์๋ ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ณ์ผ๋ก ๋ง๋ค์ง ์์ต๋๋ค. ๋ฒ์๊ฐ ์ง์ ๋ ์ฐธ์กฐ๋ฅผ ์ฌ์ฉํ๋ฉด ํธ์ถ์์ ๊ฐ์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
void Add(scoped ref int value) { value += 2; }
int count = 3;
Add(ref count);
System.Console.WriteLine(count);๊ฒฐ๊ณผ:
5
static int Sum(scoped ReadOnlySpan<int> values);
static void Add(scoped ref int value, int amount);using System;
internal static class Program
{
public static void Main()
{
ReadOnlySpan<int> readings = stackalloc int[] { 3, 5, 7 };
Console.WriteLine(Sum(readings));
}
private static int Sum(scoped ReadOnlySpan<int> values)
{
int total = 0;
foreach (int value in values) total += value;
return total;
}
}๊ฒฐ๊ณผ:
15
using System;
internal static class Program
{
public static void Main()
{
int points = 10;
Add(ref points, 4);
Add(ref points, 6);
Console.WriteLine(points);
}
private static void Add(scoped ref int value, int amount)
{
value += amount;
}
}๊ฒฐ๊ณผ:
20
๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.