[{"id":"csharpbeginner-001","courseId":"csharp-beginner","domain":"language-basics","topic":"Value types and reference types","prompt":"A teammate assigns a struct variable to a second variable, then changes a field on the second one. What happens to the first variable?","hint":"Think about what a variable holds for a value type versus a reference type.","explain":"A variable of a value type holds its own instance, while a variable of a reference type holds a reference to an instance. Think about what gets copied when one variable is assigned to another.","source":"https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/value-types","interaction":{"type":"single"},"options":[{"id":"a","text":"The first variable is unchanged, because the copy holds its own instance.","why":"A value-type variable holds its own instance, so changes made through the copy stay in the copy."},{"id":"b","text":"The first variable changes too, because both names share one object.","whyNot":"That is reference-type behavior. A struct copy holds its own data, not a shared reference."},{"id":"c","text":"The first variable changes too, because assignment only links the two variables.","whyNot":"Assignment copies a value-type instance; it does not link the two variables together."},{"id":"d","text":"The compiler rejects the change, because structs are read-only.","whyNot":"Ordinary structs allow field changes, and this edit to the copy compiles without error."}],"answer":"a","explanation":"A value-type variable holds its own instance, so assigning it copies the instance. A reference-type variable holds a reference, so copies share one object.","concept":"A value-type variable holds its own instance, so assigning it copies the instance. A reference-type variable holds a reference, so copies share one object.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"public struct Point { public int X; }\nvar p1 = new Point();\nvar p2 = p1;\np2.X = 200;","takeaways":["Assigning a struct copies its data; assigning a class copies only the reference."]},{"id":"csharpbeginner-002","courseId":"csharp-beginner","domain":"language-basics","topic":"Implicitly typed local variables","prompt":"The statement `var a = 32;` makes the compiler infer the type of a from the number 32, so a.GetType() reports System.Int32.","hint":"Think about where the compiler takes the variable's type from when you write var instead of a type name.","explain":"The var keyword asks the compiler to choose a local's type from the expression that initializes it. Consider which type a whole-number literal gives the variable.","source":"https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/declarations","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"The compiler infers the type from the literal 32, and GetType reports that type as System.Int32."},{"id":"b","text":"False","whyNot":"var does not leave the variable untyped or generic; the compiler picks one concrete type from the initializer."}],"answer":"a","explanation":"Implicitly typed local variables are strongly typed: with var, the compiler infers one type for the local from its initialization expression. For var a = 32;, that type is System.Int32.","concept":"Implicitly typed local variables are strongly typed: with var, the compiler infers one type for the local from its initialization expression. For var a = 32;, that type is System.Int32.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"var a = 32;\nConsole.WriteLine(a.GetType());","takeaways":["var is shorthand for a type the compiler infers from the initializer."]},{"id":"csharpbeginner-003","courseId":"csharp-beginner","domain":"language-basics","topic":"String interpolation","prompt":"The app runs on a machine set to nl-NL. The code is $\"Speed: {speed:N3}\". Which setting decides the separators used in the formatted number?","hint":"Look at which culture object formatting reads when you don't pass one.","explain":"An interpolated string turns values into text using a culture, which sets separators and symbols. Think about how formatting chooses that culture when you don't pass one, and what the running code can change.","source":"https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated","interaction":{"type":"single"},"options":[{"id":"a","text":"CultureInfo.CurrentCulture","why":"An interpolated string formats with the current culture by default, so the nl-NL separators apply."},{"id":"b","text":"CultureInfo.InvariantCulture","whyNot":"Invariant formatting has to be requested, for example with string.Create. It is not the default."},{"id":"c","text":"CultureInfo.CurrentUICulture","whyNot":"UI culture chooses resource strings for display. Number formatting in the interpolation uses CurrentCulture."},{"id":"d","text":"The culture the source file was compiled with","whyNot":"The default is read at run time from the current culture, not fixed when the code is compiled."}],"answer":"a","explanation":"An interpolated string formats values with CultureInfo.CurrentCulture by default. InvariantCulture must be requested explicitly, for example through string.Create.","concept":"An interpolated string formats values with CultureInfo.CurrentCulture by default. InvariantCulture must be requested explicitly, for example through string.Create.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"double speed = 299792.458;\nstring s = $\"Speed: {speed:N3}\";","takeaways":["Pass an explicit culture when the output must match on every machine."]},{"id":"csharpbeginner-004","courseId":"csharp-beginner","domain":"language-basics","topic":"Null-conditional member access","prompt":"The code reads customer?.Address.City, and customer is null. What does the whole expression produce?","hint":"Think about what happens to the rest of a chain once one link is null.","explain":"The ?. operator checks its left operand for null before going on. Think about whether the members after it still run when that check finds null.","source":"https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/member-access-operators","interaction":{"type":"single"},"options":[{"id":"a","text":"null, and neither Address nor City is evaluated","why":"A null left operand short-circuits the rest of the chain, so no further member is accessed."},{"id":"b","text":"A NullReferenceException, because Address is read from a null customer","whyNot":"A plain customer.Address.City would throw here, but the ?. operator prevents that access."},{"id":"c","text":"The default value of City's type, such as 0 or an empty string","whyNot":"The operator produces null when the left side is null, not a default value of the member's type."},{"id":"d","text":"The Address object, with City left unset","whyNot":"The chain stops at the null check, so there is no Address object to return."}],"answer":"a","explanation":"For a?.B.C(), if a is null then B is not evaluated and C() is not called; the null-conditional operator short-circuits the rest of the chain and the result is null.","concept":"For a?.B.C(), if a is null then B is not evaluated and C() is not called; the null-conditional operator short-circuits the rest of the chain and the result is null.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"Customer? customer = null;\nvar city = customer?.Address.City;","takeaways":["?. stops the whole chain at the first null, so place it where null is possible."]},{"id":"csharpbeginner-005","courseId":"csharp-beginner","domain":"language-basics","topic":"Null-coalescing operators","prompt":"Which TWO of these statements about the ?? and ??= operators are true?","hint":"Think about when each operator looks at its right-hand side.","explain":"?? checks its left operand for null and only then looks at the right side. ??= is shorthand that assigns based on the same null test. Consider which values count as null.","source":"https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-coalescing-operator","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"The ?? operator does not evaluate its right-hand operand when the left-hand operand is non-null.","why":"A non-null left operand is returned straight away, so the right side is skipped."},{"id":"b","text":"The ??= operator assigns its right-hand operand to the left only when the left is null.","why":"??= replaces the pattern of checking for null and then assigning, so it assigns only when the left is null."},{"id":"c","text":"The ?? operator treats an empty string on the left as null and returns the right side.","whyNot":"?? tests only for null. An empty string is a non-null value, so it is returned as it is."},{"id":"d","text":"You can write int x = 5; x ?? 0, because ?? also accepts non-nullable value types.","whyNot":"The left operand of ?? can't be a non-nullable value type, so this line doesn't compile."},{"id":"e","text":"You can overload ?? and ??= in your own class to change how they behave.","whyNot":"The ?? and ??= operators can't be overloaded."},{"id":"f","text":"The ??= operator evaluates its right-hand operand even when the left one is non-null.","whyNot":"??= doesn't evaluate its right-hand operand when the left-hand operand is non-null."}],"answer":"ab","explanation":"?? returns its left operand unless that operand is null, and skips the right operand when the left is non-null. ??= assigns only when the left operand is null.","concept":"?? returns its left operand unless that operand is null, and skips the right operand when the left is non-null. ??= assigns only when the left operand is null.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["?? tests only for null, not for empty strings or other default-looking values."]}]