C# Next (C# 12 후보) - slog(μ™„λ£Œ)

μ œλ„€λ¦­λ„ 별칭이 λ©λ‹ˆλ‹€.

2 Likes

ν† λ‘  에도 μ–ΈκΈ‰λ˜μžˆλŠ”λ°,

using IEn<T> = System.Collections.Generic.IEnumerable<T>;
IEn<int> arr = new int[4];

μ΄λŸ°λŠλ‚ŒμœΌλ‘œ μ œλ„€λ¦­ν΄λž˜μŠ€μ˜ μ΄λ¦„λ§Œ λ°”κΎΈλ©΄μ„œ μ œλ„€λ¦­νŒŒλΌλ―Έν„°λ₯Ό μ΄μš©ν•˜κ³ μ‹Άμ–΄μš”

2 Likes

μ•„ 이런 ν˜•νƒœλ₯Ό λ§μ”€ν•˜μ‹œλŠ” κ΅°μš”.

using L<TValue> = System.Collections.Generic.List<TValue>;

이런 ν˜•νƒœλŠ” (아직) μ§€μ›ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

2 Likes

λ°˜μžλ™ 속성(Semi Auto Properties)이 C# 12에 ν¬ν•¨λ˜μ§€ μ•ŠλŠ” 것 κ°™λ„€μš”. κ½€ κΈ°λ‹€λ¦¬λ˜ κΈ°λŠ₯ μ΄μ—ˆλŠ”λ° μ•„μ‰½μŠ΅λ‹ˆλ‹€.

3 Likes

μ •μ„±νƒœλ‹˜μ˜ C# 12 κ΄€λ ¨ κΈ€:

3 Likes

λ‹·λ„·: 2150. C# 12 - 정적 λ¬Έλ§₯μ—μ„œ μΈμŠ€ν„΄μŠ€ 멀버에 λŒ€ν•œ nameof μ ‘κ·Ό ν—ˆμš©(Allow nameof to always access instance members from static context) (sysnet.pe.kr)

λ‹·λ„·: 2151. C# 12 - ref readonly λ§€κ°œλ³€μˆ˜ (sysnet.pe.kr)

3 Likes

Experimental Attribute

μ•„ 이게 .NET 8이 μ•„λ‹ˆλΌ C# 12의 κΈ°λŠ₯ μ΄μ˜€κ΅°μš”. Experimental νŠΉμ„±μ„ μ‚¬μš©ν•˜μ—¬ κ΅¬ν˜„ν•˜λ©΄ μ‚¬μš© μ‹œ μ‹€ν—˜μ  κΈ°λŠ₯μ΄λΌλŠ” 컴파일 였λ₯˜μ™€ ν•¨κ»˜ 주의 ν•΄μ„œ μ‚¬μš©ν•  것을 μ•Œλ €μ€λ‹ˆλ‹€.

κ·ΈλŸΌμ—λ„ λΆˆκ΅¬ν•˜κ³  μ‚¬μš©ν•˜κΈ°λ₯Ό μ›ν•œλ‹€λ©΄ #pragma warning disable MING01 등을 μ΄μš©ν•΄μ„œ κ΄€λ ¨ 였λ₯˜λ₯Ό λ¬΄μ‹œν•  수 μžˆμŠ΅λ‹ˆλ‹€.

2 Likes

개인적으둜 .net 8μ—μ„œ κ°€μž₯ μ“°κ³  μ‹Άμ—ˆλ˜ κΈ°λŠ₯이 using type μž…λ‹ˆλ‹€.

using Tuple = (int a, int b);

namespace ConsoleApp11;

internal class Program
{
    static void Main(string[] args)
    {
        Tuple tuple = new(1, 2);
        Console.WriteLine(tuple.a + "/" + tuple.b);
    }
}

이게 .net 7μ—μ„œλŠ” μ•ˆλ˜μ§€λ§Œ 8에 λ„μž… λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

C++ λ•Œ typedef λ₯Ό μ“°λ˜κ²Œ 생각 λ‚˜λ„€μš”.

4 Likes

μ»¬λ ‰μ…˜ ν‘œν˜„μ‹μ„ μ‚¬μš©ν•  λ•Œ λ‹€μŒ 처럼,

Span<int> list = [1, 2, 3, 4, 5];

Span으둜 μ»¬λ ‰μ…˜μ„ 생성할 경우 μ •λ§λ‘œ μŠ€νƒμ— ν• λ‹Ήν•˜λŠ”μ§€ κΆκΈˆν•΄μ„œ BenchmarkDotNet을 μ΄μš©ν•΄ λ‹€μŒ 처럼 κ΅¬μ„±ν•œ ν›„ 확인해 λ³΄μ•˜μŠ΅λ‹ˆλ‹€.

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;

namespace Benchmark;

[SimpleJob(RuntimeMoniker.Net80)]
[RPlotExporter]
[MemoryDiagnoser]
public class CSharp12
{
    [Params(10000)]
    public int Count;

    [Benchmark]
    public void CollectionExpressionsArray()
    {
        for (var i = 0; i < Count; i++)
        {
            int[] list = [1, 2, 3, 4, 5];
            list[0] = 1;
        }
    }

    [Benchmark]
    public void CollectionExpressionsSpan()
    {
        for (var i = 0; i < Count; i++)
        {
            Span<int> list = [1, 2, 3, 4, 5];
            list[0] = 1;
        }
    }
}
| Method                     | Count | Mean      | Error     | StdDev    | Gen0    | Allocated |
|--------------------------- |------ |----------:|----------:|----------:|--------:|----------:|
| CollectionExpressionsArray | 10000 | 29.108 us | 0.5588 us | 0.5979 us | 38.2385 |  480000 B |
| CollectionExpressionsSpan  | 10000 |  8.099 us | 0.0180 us | 0.0160 us |       - |         - |

였, μ •λ§λ‘œ μŠ€νƒμ— ν• λ‹Ήλ˜λŠ”κ΅°μš”.

5 Likes

λ‹€μŒμ˜ 경둜λ₯Ό 톡해 C# 12μ—μ„œ μΆ”κ°€λœ κΈ°λŠ₯을 μ½”λ“œλ‘œ μ‚΄νŽ΄λ³Ό 수 μžˆμŠ΅λ‹ˆλ‹€.

4 Likes
3 Likes
2 Likes