KO CSharp Keyword params - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
๋ค์ํ ์์ ์ธ์๋ก ํธ์ถํ ์ ์์ต๋๋ค. ๋ฐฐ์ด ๋๋ ์ง์๋๋ ์ปฌ๋ ์ ํ์์ ์ ๋ฌํฉ๋๋ค. ๋ฉ์๋์ ๋ง์ง๋ง ๋งค๊ฐ๋ณ์์ ๋๋ค.
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
int Sum(params int[] values)
{
int total = 0;
foreach (int value in values) total += value;
return total;
}
System.Console.WriteLine(Sum(1, 2, 3));๊ฒฐ๊ณผ:
6
Method(params int[] values) / Method(params ReadOnlySpan<int> values)params ์ปฌ๋ ์ ์ C# 13์์ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ด์ ๋ฒ์ ์ ์ธ์ด์๋ ๋๊ท๋ชจ ํ์์ด ์กด์ฌํฉ๋๋ค.
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)
{
Console.WriteLine(Numbers.Sum(1, 2, 3));
Console.WriteLine(Numbers.Sum(new int[] { 4, 5 }));
}
}
public static class Numbers { public static int Sum(params int[] values) => values.Sum(); }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)
{
Console.WriteLine(Numbers.Sum(2, 4, 6));
}
}
public static class Numbers { public static int Sum(params ReadOnlySpan<int> values) { int sum = 0; foreach (int value in values) sum += value; return sum; } }๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.