dimohy
March 18, 2023, 11:36pm
1
C# 12μ λμ
λ μμ μΈ κΈ°λ₯μ λν΄ μ΄ν΄λ΄
λλ€.
Language Feature Status
=====
This document reflects the status, and planned work in progress, for the compiler team. It is a live document
and will be updated as work progresses, features are added / removed, and as work on feature progresses.
This is not an exhaustive list of our features but rather the ones which have active development
efforts behind them.
# C# Next
| Feature | Branch | State | Developer | Reviewer | LDM Champ |
| ------- | ------ | ----- | --------- | -------- | --------- |
| [Using aliases for any type](https://github.com/dotnet/csharplang/issues/4284) | [UsingAliasTypes](https://github.com/dotnet/roslyn/tree/features/UsingAliasTypes) | [Merged into 17.6.P3](https://github.com/dotnet/roslyn/issues/56323) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) | [jcouv](https://github.com/jcouv) [cston](https://github.com/cston) | |
| [Primary Constructors](https://github.com/dotnet/csharplang/issues/2691) | [PrimaryConstructors](https://github.com/dotnet/roslyn/tree/features/PrimaryConstructors) | [Merged into 17.6.P2](https://github.com/dotnet/roslyn/issues/65697) | [AlekseyTs](https://github.com/AlekseyTs) | [cston](https://github.com/cston), [jjonescz](https://github.com/jjonescz) | [MadsTorgersen](https://github.com/MadsTorgersen) |
| [Semi-auto-properties](https://github.com/dotnet/csharplang/issues/140) | [semi-auto-props](https://github.com/dotnet/roslyn/tree/features/semi-auto-props) | [In Progress](https://github.com/dotnet/roslyn/issues/57012) | [Youssef1313](https://github.com/Youssef1313) | [333fred](https://github.com/333fred), [RikkiGibson](https://github.com/RikkiGibson) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) |
| [Params Span\<T> + Stackalloc any array type](https://github.com/dotnet/csharplang/issues/1757) | [params-span](https://github.com/dotnet/roslyn/tree/features/params-span) | [In Progress](https://github.com/dotnet/roslyn/issues/57049) | [cston](https://github.com/cston) | TBD | [jaredpar](https://github.com/jaredpar) |
| [nameof accessing instance members](https://github.com/dotnet/roslyn/issues/40229) | main | [In Progress](https://github.com/dotnet/roslyn/pull/48754) | [YairHalberstadt ](https://github.com/YairHalberstadt) | [333fred](https://github.com/333fred), [AlekseyTs](https://github.com/AlekseyTs) | [333fred](https://github.com/333fred) |
| [Lambda default parameters](https://github.com/dotnet/csharplang/issues/6051) | [lambda-default-parameters](https://github.com/dotnet/roslyn/tree/features/lambda-default-parameters) | [Merged into 17.5p2](https://github.com/dotnet/roslyn/issues/62485) | [adamperlin](https://github.com/adamperlin), [jjonescz](https://github.com/jjonescz) | [333fred](https://github.com/333fred), [cston](https://github.com/cston) | [captainsafia](https://github.com/captainsafia) |
| [Default in deconstruction](https://github.com/dotnet/roslyn/pull/25562) | [decon-default](https://github.com/dotnet/roslyn/tree/features/decon-default) | [In Progress](https://github.com/dotnet/roslyn/issues/25559) | [jcouv](https://github.com/jcouv) | [gafter](https://github.com/gafter) | [jcouv](https://github.com/jcouv) |
| [Collection Literals](https://github.com/dotnet/csharplang/issues/5354) | [CollectionLiterals](https://github.com/dotnet/roslyn/tree/features/CollectionLiterals) | [In Progress](https://github.com/dotnet/roslyn/issues/66418) | [cston](https://github.com/cston) | [333fred](https://github.com/333fred), [RikkiGibson](https://github.com/RikkiGibson) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) |
This file has been truncated. show original
κΈ°λ₯μ΄ κ΅¬νλμμ λλ§λ€ λ΄μ©μ μ΄ν΄λ³΄λλ‘ νκ² μ΅λλ€.
5 Likes
dimohy
March 18, 2023, 11:50pm
2
C# 12μ μ΄μ λ€μμ μ½λκ° ν©λ²μ
λλ€.
using Point = (int X, int Y);
# Allow using alias directive to reference any kind of Type
## Summary
Relax the using_alias_directive ([Β§13.5.2](https://github.com/dotnet/csharpstandard/blob/draft-v6/standard/namespaces.md#1352-using-alias-directives)) to allow it to point at any sort of type, not just named types. This would support types not allowed today, like: tuple types, pointer types, array types, etc. For example, this would now be allowed:
```c#
using Point = (int x, int y);
```
## Motivation
For ages, C# has had the ability to introduce aliases for namespaces and named types (classes, delegated, interfaces, records and structs). This worked acceptably well as it provided a means to introduce non-conflicting names in cases where a normal named pulled in from `using_directive`s might be ambiguous, and it allowed a way to provide a simpler name when dealing with complex generic types. However, the rise of additional complex type symbols in the language has caused more use to arise where aliases would be valuable but are currently not allowed. For example, both tuples and function-pointers often can have large and complex regular textual forms that can be painful to continually write out, and a burden to try to read. Aliases would help in these cases by giving a short, developer-provided, name that can then be used in place of those full structural forms.
## Detailed design
We will change the grammar of `using_alias_directive` thusly:
```
using_alias_directive
- : 'using' identifier '=' namespace_or_type_name ';'
+ : 'using' identifier '=' (namespace_name | type) ';'
;
This file has been truncated. show original
3 Likes
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>
# Primary constructors
## Summary
[summary]: #summary
Classes and structs can have a parameter list, and their base class specification can have an argument list.
Primary constructor parameters are in scope throughout the class or struct declaration, and if they are captured by a function member or anonymous function, they are appropriately stored (e.g. as unspeakable private fields of the declared class or struct).
The proposal "retcons" the primary constructors already available on records in terms of this more general feature with some additional members synthesized.
## Motivation
[motivation]: #motivation
The ability of a class or struct in C# to have more than one constructor provides for generality, but at the expense of some tedium in the declaration syntax, because the constructor input and the class state need to be cleanly separated.
Primary constructors put the parameters of one constructor in scope for the whole class or struct to be used for initialization or directly as object state. The trade-off is that any other constructors must call through the primary constructor.
``` c#
public class C(bool b, int i, string s) : B(b) // b passed to base constructor
{
This file has been truncated. show original
3 Likes
dimohy
March 19, 2023, 12:11am
4
C# 12μμλ μ΄μ λλ€μμ κΈ°λ³Έ λ§€κ°λ³μλ₯Ό μ¬μ©ν μ μμ΅λλ€.
var addWithDefault = (int addTo = 2) => addTo + 1;
addWithDefault(); // 3
addWithDefault(5); // 6
# Optional and parameter array parameters for lambdas and method groups
## Summary
[summary]: #summary
To build on top of the lambda improvements introduced in C# 10 (see [relevant background](#relevant-background)), we propose adding support for default parameter values and `params` arrays in lambdas. This would enable users to implement the following lambdas:
```csharp
var addWithDefault = (int addTo = 2) => addTo + 1;
addWithDefault(); // 3
addWithDefault(5); // 6
var counter = (params int[] xs) => xs.Length;
counter(); // 0
counter(1, 2, 3); // 3
```
Similarly, we will allow the same kind of behavior for method groups:
```csharp
This file has been truncated. show original
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 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
μ μ¬μ©νκ² λ©λλ€.
# Collection expressions
## Summary
[summary]: #summary
Collection expressions introduce a new terse syntax, `[e1, e2, e3, etc]`, to create common collection values. Inlining other collections into these values is possible using a spread operator `..` like so: `[e1, ..c2, e2, ..c2]`. A `[k1: v1, ..d1]` form is also supported for creating dictionaries.
Several collection-like types can be created without requiring external BCL support. These types are:
* [Array types](https://github.com/dotnet/csharplang/blob/main/spec/types.md#array-types), such as `int[]`.
* [`Span<T>`](https://learn.microsoft.com/en-us/dotnet/api/system.span-1) and [`ReadOnlySpan<T>`](https://learn.microsoft.com/en-us/dotnet/api/system.readonlyspan-1).
* Types that support [collection initializers](https://github.com/dotnet/csharplang/blob/main/spec/expressions.md#collection-initializers), such as [`List<T>`](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1) and [`Dictionary<TKey, TValue>`](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2).
Further support is present for collection-like types not covered under the above, such as [`ImmutableArray<T>`](https://learn.microsoft.com/en-us/dotnet/api/system.collections.immutable.immutablearray-1), through a new API pattern that can be adopted directly on the type itself or through extension methods.
## Motivation
[motivation]: #motivation
* Collection-like values are hugely present in programming, algorithms, and especially in the C#/.NET ecosystem. Nearly all programs will utilize these values to store data and send or receive data from other components. Currently, almost all C# programs must use many different and unfortunately verbose approaches to create instances of such values. Some approaches also have performance drawbacks. Here are some common examples:
- Arrays, which require either `new Type[]` or `new[]` before the `{ ... }` values.
This file has been truncated. show original
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