Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Front Back
- What major feature in C# 7 allows returning multiple values from a method? Value Tuples: `(int, string) GetValues() => (42, "Hello");`
- How do you deconstruct a tuple in C# 7? Using `var (x, y) = GetValues();`
- What is pattern matching in C# 7? A feature that allows checking an object’s type and extracting data in a `switch` or `if` statement.
- What is a local function in C# 7? A method declared inside another method to encapsulate logic.
- How do `out` variables work in C# 7? They can be declared inline: `if (int.TryParse(str, out int result)) { }`
- What does `ref return` do in C# 7? It allows returning a reference instead of a value: `ref int GetRef() => ref myArray[0];`
- What is an expression-bodied constructor in C# 7? A shorthand constructor: `public MyClass(string name) => Name = name;`
- How does `throw` work in expressions in C# 7? `throw` can now be used inline: `return x ?? throw new ArgumentNullException();`
- What are default literals in C# 7.1? `default` can infer its type: `int x = default;`
- What is `async Main()` in C# 7.1? It allows `Main()` to return a `Task`: `static async Task Main() { await SomeMethod(); }`
- What are inferred tuple element names in C# 7.1? Tuple elements automatically get variable names: `var tuple = (age, name);`
- What is the `Span<T>` type introduced in C# 7.2? A high-performance, stack-allocated slice of an array.
- What is the `in` modifier in C# 7.2? It passes arguments by reference but prevents modification inside the method.
- What is `readonly struct` in C# 7.2? A struct that prevents modification after creation.
- What does `private protected` do in C# 7.2? It allows access only within the same class or derived classes inside the same assembly.
- What is the `switch` expression in C# 8? A concise `switch` replacement: `var result = x switch { 1 => "One", _ => "Other" };`
- How do ranges work in C# 8? Using `..`: `int[] slice = arr[1..4];`
- What is an `index` from end in C# 8? Using `^`: `int last = arr[^1];`
- What is a nullable reference type in C# 8? A feature that enables warnings for potential `null` references.
- How do you enable nullable reference types in C# 8? Add `#nullable enable` or `<Nullable>enable</Nullable>` in `.csproj`.
- What are `async streams` in C# 8? They allow `await foreach`: `async IAsyncEnumerable<int> GetNumbers() { yield return 1; }`
- What is the purpose of `using` declarations in C# 8? They dispose of objects automatically at the end of the scope: `using var reader = new StreamReader("file.txt");`
- What is a default interface method in C# 8? A method in an interface that has a default implementation.
- What are `record` types in C# 9? Immutables with value-based equality: `public record Person(string Name, int Age);`
- How do `init` accessors work in C# 9? They allow setting properties only at object initialization: `public string Name { get; init; }`
- What are top-level statements in C# 9? They remove the need for `Main()`: `Console.WriteLine("Hello, World!");`
- What is the `with` expression in C# 9? It creates a modified copy of an immutable record: `var newPerson = person with { Age = 30 };`
- What is a target-typed `new()` in C# 9? It allows `var x = new();` when the type is clear from context.
- What is a file-scoped namespace in C# 10? A shorthand for namespaces: `namespace MyNamespace;`
- What are `record struct` types in C# 10? Immutable value types similar to `record` but stored on the stack.
- What are `global using` directives in C# 10? They allow project-wide `using` statements: `global using System;`
- What improvements were made to lambdas in C# 10? Lambdas can now have natural type inference and attributes.
- What is the `required` keyword in C# 11? It forces properties to be initialized: `public required string Name { get; set; }`
- What are raw string literals in C# 11? Multi-line string literals using `"""` instead of `@""`.
- What is list pattern matching in C# 11? Matching arrays/lists with patterns: `arr is [1, 2, 3]`
- What is `Span<T>.Empty` in C# 11? A performance optimization for empty spans.
- What is `using alias` for any type in C# 12? It allows `using MyAlias = MyNamespace.MyClass;` for all types.
- What are `default lambda parameters` in C# 12? Lambdas can have default values: `Func<int, int> f = (x = 5) => x * 2;`
- What are `collection expressions` in C# 12? They simplify array creation: `int[] nums = [1, 2, 3];`
- What is a `primary constructor` in C# 12? A constructor declared at the class level: `public class MyClass(string Name, int Age);`
- What is `interceptors` (experimental) in C# 12? A feature that allows modifying method calls dynamically.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement