KO CSharp Keyword in - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki

ะฃะบั€ะฐั—ะฝััŒะบะฐ ยท ะ ัƒััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซ”ไธญๆ–‡ ยท ๆ—ฅๆœฌ่ชž ยท ํ•œ๊ตญ์–ด

C#: in

ํ•ธ๋“œ๋ถ C# ยท ์‹ค์šฉ ๊ฐ€์ด๋“œ

๋งค๊ฐœ๋ณ€์ˆ˜์—๋Š” ์ฝ๊ธฐ ์ „์šฉ ๋งํฌ๊ฐ€ ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค. ์ผ๋ฐ˜ ์„ ์–ธ์—์„œ ๋ฐ˜๊ณต๋ณ€์„ฑ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. foreach ๋ฐ LINQ์—์„œ๋Š” ์š”์†Œ๋ฅผ ์‹œํ€€์Šค์—์„œ ๋ถ„๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

๊ฐ„๋‹จํ•œ ์˜ˆ์ œ (Example.cs)

์ด ์˜ˆ์ œ๋ฅผ Example.cs๋กœ ๋”ฐ๋กœ ์ €์žฅํ•˜๊ณ  ์ด ํŽ˜์ด์ง€์˜ ๋‹ค๋ฅธ ์˜ˆ์ œ์™€ ๋…๋ฆฝ์ ์œผ๋กœ ์‹คํ–‰ํ•˜์„ธ์š”.

Example.cs:

// PROJECT-EXAMPLE
int Double(in int value) => value * 2;
int count = 3;
System.Console.WriteLine(Double(in count));

๊ฒฐ๊ณผ:

6

ํ†ต์‚ฌ๋ก 

Method(in value) / interface IConsumer<in T> / foreach (var x 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)
    {
        Point value = new(2, 3);
        Console.WriteLine(Geometry.Sum(in value));
    }
}
public readonly record struct Point(int X, int Y);
public static class Geometry { public static int Sum(in Point value) => value.X + value.Y; }

์˜ˆ 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)
    {
        IConsumer<object> broad = new Writer();
        IConsumer<string> narrow = broad;
        narrow.Accept("ore");
    }
}
public interface IConsumer<in T> { void Accept(T value); }
public class Writer : IConsumer<object> { public void Accept(object value) { Console.WriteLine(value); } }

๊ณต์‹ ์ถœ์ฒ˜: Microsoft ํ•™์Šต.

โš ๏ธ **GitHub.com Fallback** โš ๏ธ