dimohy
March 19, 2023, 12:08am
3
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
3 Likes
dimohy
March 19, 2023, 12:11am
4
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
6 Likes
dimohy
April 12, 2023, 1:41am
6
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);
2 Likes
dimohy
April 12, 2023, 2:51am
7
2 Likes
dimohy
April 14, 2023, 1:32am
8
2 Likes
dimohy
April 18, 2023, 12:49pm
9
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 μ΄ν λΆν°λ μ΄ μ»΄νμΌ μ€λ₯λ λ°μνμ§ μμ΅λλ€.
3 Likes
dimohy
May 11, 2023, 11:25pm
12
1 Like
dimohy
May 11, 2023, 11:26pm
13
1 Like
dimohy
May 11, 2023, 11:26pm
14
2 Likes
dimohy
May 17, 2023, 1:07am
15
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
3 Likes
dimohy
July 19, 2023, 12:44pm
17
C# 12μ κΈ°λ₯μ΄ κ±°μ νμ λμμ΅λλ€. κ½€ λ§μ κΈ°λ₯μ΄ C# 12μμ μ μΈλλ€λ μ¬μ€μ΄ μ½κ° μ¬νλ€μ.
νΉν λ°μλ μμ±(Semi auto properties)μ κ²½μ° κ½€ λ§μ΄ μ¬μ©ν κΈ°λ₯μ΄λΌ μ΄μ λ²μ λΆν° κΈ°λ€λ Έλλ° μμΈλ‘ ꡬνμ΄ μ΄λ €μ΄κ° λ΄
λλ€.
2 Likes
dimohy
July 20, 2023, 12:02pm
18
λλμ΄ μ»¬λ μ
리ν°λ΄μ΄ 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
2 Likes
dimohy
July 26, 2023, 12:02am
19
λλμ΄ μ»¬λ μ
ννμμ 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];
6 Likes
μ λ€λ¦λ³μΉμ μμ§μΈκ°λ³΄κ΅°μ
2 Likes
dimohy
July 26, 2023, 3:46am
21
μ λ€λ¦λ λ³μΉμ΄ λ©λλ€.
2 Likes
ν λ‘ μλ μΈκΈλμλλ°,
using IEn<T> = System.Collections.Generic.IEnumerable<T>;
IEn<int> arr = new int[4];
μ΄λ°λλμΌλ‘ μ λ€λ¦ν΄λμ€μ μ΄λ¦λ§ λ°κΎΈλ©΄μ μ λ€λ¦νλΌλ―Έν°λ₯Ό μ΄μ©νκ³ μΆμ΄μ
2 Likes