C# 12μ λμ λ μμ μΈ κΈ°λ₯μ λν΄ μ΄ν΄λ΄ λλ€.
κΈ°λ₯μ΄ κ΅¬νλμμ λλ§λ€ λ΄μ©μ μ΄ν΄λ³΄λλ‘ νκ² μ΅λλ€.
C# 12μ λμ λ μμ μΈ κΈ°λ₯μ λν΄ μ΄ν΄λ΄ λλ€.
κΈ°λ₯μ΄ κ΅¬νλμμ λλ§λ€ λ΄μ©μ μ΄ν΄λ³΄λλ‘ νκ² μ΅λλ€.
C# 12μ μ΄μ λ€μμ μ½λκ° ν©λ²μ λλ€.
using Point = (int X, int Y);
https://github.com/dotnet/csharplang/blob/main/proposals/using-alias-types.md
C# 12μ μ΄μ λ€μμ μ½λμ κ°μ΄ class, structμμ μμ±μ 맀κ°λ³μλ₯Ό μ§μ ν μ μμΌλ©° λ΄λΆμμ μ¬μ©ν κ²½μ° μ μ νκ² private νλλ‘ μΊ‘μ³ λ©λλ€.
class TestClass(int x, int y);
recordμ λ€λ₯Έ μ μ x
μ y
κ° μΈλΆλ‘ λ
ΈμΆλμ§ μλλ€λ μ μ
λλ€.
Visual Studioμ μ΅μ 미리보기 λΉλλ‘ csporjμ λ€μμ μ€μ μ ν ν νμΈμ΄ κ°λ₯ν©λλ€.
<PropertyGroup>
<LangVersion>Preview</LangVersion>
</PropertyGroup>
https://github.com/dotnet/csharplang/blob/main/proposals/primary-constructors.md
C# 12μμλ μ΄μ λλ€μμ κΈ°λ³Έ 맀κ°λ³μλ₯Ό μ¬μ©ν μ μμ΅λλ€.
var addWithDefault = (int addTo = 2) => addTo + 1;
addWithDefault(); // 3
addWithDefault(5); // 6
https://github.com/dotnet/csharplang/blob/main/proposals/lambda-method-group-defaults.md
Visual Studio 2022 17.6 P3μ΄ μΆμλλ©΄μ μ΄μ λ―Έλ¦¬λ³΄κΈ°λ‘ νμΈν μ μμ΅λλ€.
<PropertyGroup>
<LangVersion>preview</LangVersion>
</PropertyGroup>
using Point = (int X, int Y);
Point x = (10, 15);
Point y = (20, 12);
var z = new Point(x.X + y.X, x.Y + y.Y);
Console.WriteLine(z);
using System;
public struct C {
public string P;
public static string M1() => nameof(P); // Legal
public static string M2() => nameof(P.Length); // error CS0120: An object reference is required for the non-static field, method, or property 'C.P'
}
μμ μ½λμ κ°μ΄ μ μ 컨ν μ€νΈμμ μΈμ€ν΄μ€ λ©€λ²μ μμΈμ€ ν κ²½μ° μ»΄νμΌ μ€λ₯κ° λ°μνλ κ²½μ°κ° μμ΅λλ€.
17.7 P1 μ΄ν λΆν°λ μ΄ μ»΄νμΌ μ€λ₯λ λ°μνμ§ μμ΅λλ€.
VS 17.7p1μ΄ λ¦΄λ¦¬μ€ λλ©΄μ κ°μ λ κΈ°λ₯μ ν μ€νΈν μ μκ² λμμ΅λλ€. μ΄μ μΈμ€ν΄μ€ λ©€λ²λ nameof λμμΌλ‘ μ¬μ©ν μ μμ΅λλ€.
Console.WriteLine(C.M1());
Console.WriteLine(C.M2());
public struct C
{
public string P;
public static string M1() => nameof(P); // Legal
public static string M2() => nameof(P.Length); // error CS0120: An object reference is required for the non-static field, method, or property 'C.P'
}
| μΆλ ₯
P
Length
C# 12μ κΈ°λ₯μ΄ κ±°μ νμ λμμ΅λλ€. κ½€ λ§μ κΈ°λ₯μ΄ C# 12μμ μ μΈλλ€λ μ¬μ€μ΄ μ½κ° μ¬νλ€μ.
νΉν λ°μλ μμ±(Semi auto properties)μ κ²½μ° κ½€ λ§μ΄ μ¬μ©ν κΈ°λ₯μ΄λΌ μ΄μ λ²μ λΆν° κΈ°λ€λ Έλλ° μμΈλ‘ ꡬνμ΄ μ΄λ €μ΄κ° λ΄
λλ€.
λλμ΄ μ»¬λ μ
리ν°λ΄μ΄ C#μ λμ
λλκ΅°μ. νλ§λλ‘ μ΄μ λͺ©λ‘μ [1, 2, 3] ννλ‘ μΈ μ μκ² λ©λλ€.
μ¬μ νμλ [key: value, β¦]λ‘ μ¬μ©ν μ μμ΅λλ€.
λ¨μν μ€κ΄νΈμμ λκ΄νΈλ‘ λ³κ²½λκ²μ΄ μλλΌ μ΄μ μλ λͺ©λ‘μ μ¬μ©νλ €λ©΄ new xx[] λ‘ ν΄μ 무쑰건 νμ μ¬μ©ν μ λ°μ μκ±°λ stackalloc
μΌλ‘ λͺ
μμ μ€ν ν λΉμ ν΄μΌ νλ€λ©΄ Span<T> μ νμΌλ‘ λ°μ κ²½μ° μμ λ¨μμ 컬λ μ
μ μ묡μ μΌλ‘ stackalloc
μ μ¬μ©νκ² λ©λλ€.
https://github.com/dotnet/csharplang/blob/main/proposals/collection-expressions.md#span-types
λλμ΄ μ»¬λ μ ννμμ Visual Studio 2022 17.7 P5μμ ν μ€νΈ ν΄ λ³Ό μ μμ΅λλ€.
<PropertyGroup>
<LangVersion>Preview</LangVersion>
</PropertyGroup>
μ΄μ μλ μ΄λ κ² μ¨μΌ νλ€λ©΄
var oList = new int[] { 1, 2, 3, 4, 5 };
μ΄μ λ λ€μκ³Ό κ°μ΄ μ¬μ©ν μ μμ΅λλ€.
int[] nList = [1, 2, 3, 4, 5];
μ€νμ λ°°μ΄μ μμ±νλ κ²λ λ€μμ²λΌ μ¬μ©ν μ μκ² λμμ΅λλ€.
Span<int> sList = [1, 2, 3, 4, 5];
ν¨ν΄μΌμΉμλ μ¬μ©ν μ μμ΅λλ€.
var result = sList is [1, .., 5];
μ λ€λ¦λ³μΉμ μμ§μΈκ°λ³΄κ΅°μ