[{"id":"csharpintermediate-001","courseId":"csharp-intermediate","domain":"language-basics","topic":"Pattern matching with is","prompt":"A switch expression matches an int input against four arms. Put these arms in the order C# evaluates them.","hint":"Consider whether a switch takes its arms in a set order.","explain":"A switch expression tests one value against its arms. The arms are examined in a fixed sequence, a guard can add a condition, and only the chosen arm's result is produced.","source":"https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/switch-expression","interaction":{"type":"sort","items":[{"text":"int n when n > 100 => \"large\"","why":"It is the top arm, so C# tests it before any arm below it."},{"text":"int n when n > 10 => \"medium\"","why":"It sits second, so C# reaches it only after the arm above it has been tested."},{"text":"int n when n > 0 => \"small\"","why":"It sits third, so C# tests it after the two arms above it."},{"text":"_ => \"none\"","why":"The discard arm comes last because it matches every value, so it must follow the others."}]},"options":[],"answer":"o:abcd","explanation":"A switch expression evaluates its arms in text order and returns the first one whose pattern matches and whose when guard, if present, is true.","concept":"A switch expression evaluates its arms in text order and returns the first one whose pattern matches and whose when guard, if present, is true.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["A switch takes the first arm, top to bottom, whose pattern matches and whose guard passes."]},{"id":"csharpintermediate-002","courseId":"csharp-intermediate","domain":"language-basics","topic":"Property patterns","prompt":"Which TWO statements about property patterns, such as `date is { Year: 2020 }`, are true?","hint":"Check what a null value does, and how far a nested pattern can reach.","explain":"A property pattern checks members of an object against nested patterns. Each nested pattern applies to one member, and the nesting can go deeper.","source":"https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/patterns","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"The pattern matches only when the value is non-null and each nested pattern matches its property or field.","why":"That is the rule: a property pattern fails on null and then tests each nested member."},{"id":"b","text":"An extended property pattern can reach a nested member, such as `segment is { Start.Y: 0 }`.","why":"Extended property patterns reference nested properties or fields directly inside the braces."},{"id":"c","text":"The empty pattern `is { }` matches null as well as every non-null value.","whyNot":"The empty property pattern matches every non-null value and never null; it works like `is not null` for a variable."},{"id":"d","text":"Each property pattern can inspect only one property.","whyNot":"A pattern can have several nested members, and extended patterns reach deeper members."},{"id":"e","text":"A property pattern calls the type's Deconstruct method to read each property.","whyNot":"Property patterns test named properties or fields directly; Deconstruct is used by positional patterns."},{"id":"f","text":"A property pattern can't declare a variable, so you need a separate line to name the value.","whyNot":"A property pattern can add a run-time type check and a variable declaration in one expression."}],"answer":"ab","explanation":"A property pattern matches a non-null value whose members each match their nested pattern; the extended form can reach nested members like Start.Y.","concept":"A property pattern matches a non-null value whose members each match their nested pattern; the extended form can reach nested members like Start.Y.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Property patterns test named members directly, so they read clearly for object shapes."]},{"id":"csharpintermediate-003","courseId":"csharp-intermediate","domain":"language-basics","topic":"Deconstruction","prompt":"A class has two Deconstruct methods. Both declare two out parameters: one with string types and the other with int types. A caller writes `var (a, b) = item;`. What happens?","hint":"Count the out parameters each method declares, then ask whether the compiler can choose one.","explain":"A type can offer several Deconstruct methods, and each out parameter becomes one component of the result. The compiler must choose one overload for each deconstruction call.","source":"https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/patterns/deconstruct","interaction":{"type":"single"},"options":[{"id":"a","text":"The compiler reports an error at the call, because the two overloads have the same number of out parameters.","why":"Overloads with the same arity are ambiguous, so the compiler cannot choose one and reports an error."},{"id":"b","text":"The compiler picks the (string, string) overload, since it is declared first.","whyNot":"Declaration order doesn't resolve the tie; the compiler reports the ambiguity instead."},{"id":"c","text":"The class fails to compile, because two methods named Deconstruct can't coexist.","whyNot":"Deconstruct can have several overloads; the error appears only at a call that is ambiguous."},{"id":"d","text":"The compiler calls both overloads and keeps the second result.","whyNot":"Deconstruction uses a single overload for the call; it never runs them all."}],"answer":"a","explanation":"Two Deconstruct overloads with the same number of out parameters are ambiguous, and the compiler reports an error at the call.","concept":"Two Deconstruct overloads with the same number of out parameters are ambiguous, and the compiler reports an error at the call.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Give Deconstruct overloads different arities so each call has one clear match."]},{"id":"csharpintermediate-004","courseId":"csharp-intermediate","domain":"language-basics","topic":"Named tuple elements","prompt":"A developer writes `var Rest = 3;` and then `var t = (1, Rest);`. Which statement is correct?","hint":"Ask whether a variable's name can always become an element name.","explain":"When a tuple is built from variables, the compiler can reuse a variable's name as the element name. Explicit names are always allowed in a tuple literal, but inferred names have exceptions.","source":"https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/value-tuples","interaction":{"type":"single"},"options":[{"id":"a","text":"The compiler won't use Rest as the element name, because Rest is a member name of a tuple type.","why":"Names that match a tuple member, such as Rest, are not projected onto element names."},{"id":"b","text":"The second element is named Rest, so t.Rest returns 3.","whyNot":"The variable name is reused only when it is not a tuple member name, and Rest is one."},{"id":"c","text":"The declaration fails, because a variable can't be named Rest.","whyNot":"Rest is a legal variable name; only its use as an inferred element name is blocked."},{"id":"d","text":"Tuple elements never take names from variables, so every element needs an explicit name.","whyNot":"Inference does happen; it simply skips names that match tuple members."}],"answer":"a","explanation":"The compiler infers a tuple element name from a variable only when that name isn't a member name of a tuple type, such as Item3, ToString or Rest.","concept":"The compiler infers a tuple element name from a variable only when that name isn't a member name of a tuple type, such as Item3, ToString or Rest.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"var Rest = 3;\nvar t = (1, Rest);","takeaways":["Name tuple elements explicitly when a variable name could clash with a tuple member."]},{"id":"csharpintermediate-005","courseId":"csharp-intermediate","domain":"language-basics","topic":"Lambda expressions","prompt":"A lambda expression that uses a local variable from its enclosing method keeps that variable available after the method returns.","hint":"Think about what a lambda needs in order to run later, after its creating method has finished.","explain":"A lambda can refer to variables in the method or type where it is written. What matters is how long those variables must stay available once the lambda is called.","source":"https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/lambda-expressions","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"A lambda stores the outer variables it refers to, so they stay usable even after they would normally go out of scope."},{"id":"b","text":"False","whyNot":"The variable is not discarded when the method returns, because the lambda keeps it for later use."}],"answer":"a","explanation":"A lambda expression captures the outer variables it refers to, storing them so they stay usable even after they would normally go out of scope.","concept":"A lambda expression captures the outer variables it refers to, storing them so they stay usable even after they would normally go out of scope.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Captured locals live as long as the lambda that captured them, so watch what a long-lived delegate keeps alive."]}]