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
- Local methods1) is variables
12345 void Foo (object x){if (x is string s)Console.WriteLine (s.Length);}cs 2) switch statement
123456789101112131415 switch (x){case int i:Console.WriteLine ("It's an int!");break;case string s:Console.WriteLine (s.Length); // We can use the s variablebreak;case bool b when b == true: // Matches only when b is trueConsole.WriteLine ("True");break;case null:Console.WriteLine ("Nothing");break;}cs
- More expression-bodied members
123456 void WriteCubes(){Console.WriteLine(Square(3));int Square(int value) => value * value;}cs
1234567891011121314 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
댓글
댓글 쓰기