C# 버전별 추가된 기능 정리


C# 2.0

- Generics
- Nullable types
- Iterators
- Anonymouse methods (람다식의 조상)
- partial classes
- static classes

C# 3.0
- LINQ (Language Integrated Query)
- Implicitly typed local variables (var keyword)
- Object initializers
- Lambda expressions
- Extension methods
- Query expressions
- Expression trees
- Automatic properties
- Partial methods

C# 4.0
- Dynamic binding
- Optional parameters and named arguments
- Type variance with generic interfaces and delegates
- COM interoperability improvements

C# 5.0
- Asynchronous functions (async and await)

C# 6.0
- Null-conditional operator
- Expression-bodied functions
- Property initializers
- Index initializers
- String interpolation
- Exception filters (when)
using static directives
- nameof

C# 7.0
- Numerical literal improvements
ex) int million = 1_000_000; (컴파일 시 "_" 무시됨)

out variables and discards

- Patterns
1) is variables
1
2
3
4
5
void Foo (object x)
{
    if (x is string s)
    Console.WriteLine (s.Length);
}
cs

2) switch statement
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
switch (x)
{
    case int i:
        Console.WriteLine ("It's an int!");
        break;
    case string s:
        Console.WriteLine (s.Length); // We can use the s variable
        break;
    case bool b when b == true// Matches only when b is true
        Console.WriteLine ("True");
        break;
    case null:
        Console.WriteLine ("Nothing");
        break;
}
cs

- Local methods
1
2
3
4
5
6
void WriteCubes()
{
    Console.WriteLine(Square(3));
 
    int Square(int value) => value * value;
}
cs

- More expression-bodied members
1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class Person
{
    string name;
 
    public Person (string name) => Name = name;
 
    public string Name
    {
        get => name;
        set => name = value ?? "";
    }
 
    ~Person () => Console.WriteLine ("finalize");
}
cs

- More expression-bodied members
- Tuples
- throw expressions

댓글

이 블로그의 인기 게시물

Morning routine - privacy policy

World Quiz - Privacy Policy

モーニングルーチン - privacy policy