C# Programming
0Loading crowd target
0Loading crowd target
7correct to beat the crowd
50 free C# Programming trivia questions with answers — science & nature quiz, new questions added Oct 2026.
C# has been a workhorse language for more than two decades, running business software, websites, mobile apps and a large share of the world's video games. It was designed at Microsoft at the turn of the millennium, and its story involves a rivalry with an older language, a change of name and a designer with a remarkable career. This quiz covers the ground an interview or a theory test usually covers. There are questions on basic syntax and first programs, on the built-in data types, and on type conversion: casts, parsing text into numbers and what happens when a value does not fit. Others deal with classes and inheritance, access levels, memory management, asynchronous code and the tools that surround the language. The questions are multiple choice and run from first-week material to details that catch out working developers. Every answer comes with a short explanation, so the quiz works as revision before an interview, a test of what a course has taught you, or a quick challenge between builds.
30 of 50 questions with answers and explanations. Play the quiz
Q 01Which game engine, launched in 2005 at an Apple developer conference, uses C# as its primary scripting language?
Unity
Unity once offered two other scripting languages, Boo and UnityScript, but retired both in favour of C#. The engine first shipped as a Mac-only product.
Q 02Which question-and-answer site for programmers, created in 2008 by Jeff Atwood and Joel Spolsky, is written in C#?
Stack Overflow
Stack Overflow runs on C# with Microsoft's SQL Server as its database. Its founders wanted a more open alternative to the question-and-answer sites that came before it.
Q 03The sharp sign in the name of C# can be read as four of which symbol, arranged two by two?
Plus signs
Plus signs fit the joke: C++ is C stepped up once, so four of them hint at a language one step beyond C++. The name also nods to music, where a sharp raises a note by a semitone.
Q 04James Gosling dismissed the newly announced C# as an imitation of which language, which he had created at Sun?
Java
Java came from Sun Microsystems, whose co-founder Bill Joy made the same charge. C#'s lead architect answered that it was no clone and sat much closer to C++ in its design.
Q 05Anders Hejlsberg, lead architect of C#, later designed which Microsoft language that compiles to JavaScript?
TypeScript
TypeScript was released to the public in October 2012, after two years of internal development at Microsoft. Its code is translated into plain JavaScript before it runs.
Q 06Which automatic process frees C# programmers from releasing memory by hand, as they would in C or C++?
Garbage collection
Garbage collection in .NET allocates and releases memory on the program's behalf. That removes classic bugs such as forgetting to free an object or touching memory that has already been freed.
Q 07Which method of the Console class prints Hello, World and then moves to a new line in a first C# program?
WriteLine
WriteLine lives in the System namespace, so its full name is System.Console.WriteLine. A directive at the top of the file lets programmers leave off the first part.
Q 08Despite the symbol in its name, C# does not begin comments with #; what starts a single-line comment instead?
Two slashes
Two slashes, written //, turn the rest of the line into a comment. Longer notes that run over several lines sit between the markers /* and */.
Q 09Which C# keyword declares a variable that can hold only true or false, and never the number 1?
bool
The bool keyword is an alias for the .NET type System.Boolean. Unlike C++, C# never turns an integer into one automatically, so a number cannot stand in for a condition.
Q 10Which method name traditionally marks the entry point of a C# program, the first code to run?
Main
Main is the entry point of a C# application, and a program can have only one entry point. Newer versions of the language let short programs leave it out by writing top-level statements instead.
Q 11Before the name C# was chosen, Microsoft's design team called the language what, a name dropped for trademark reasons?
Cool
Cool stood for C-like Object Oriented Language, the name the team used from January 1999. Microsoft had considered keeping it for the finished language.
Q 12Anders Hejlsberg, the chief designer of C#, first made his name writing which Borland compiler of the 1980s?
Turbo Pascal
Turbo Pascal sold for $49.95, about a tenth of the price of comparable products, and was known for compiling very fast. Hejlsberg had written its core in Denmark before Borland licensed it.
Q 13Which punctuation mark ends almost every C# statement, a rule the language shares with C and C++?
Semicolon
Q 21What is the C# term for converting a value type such as int to the type object, stored on the heap?
Boxing
Boxing happens automatically, while getting the value back out again requires a cast. Both steps are computationally expensive compared with a simple assignment.
Q 22Assigning a C# int to a long variable needs no cast syntax; what is this kind of conversion called?
Implicit
Implicit conversions always succeed, so the compiler performs them silently. Going the other way, from long to int, risks losing data and has to be requested with a cast.
Q 23When a C# double such as 9.99 is cast to int, what happens to the fractional part of the number?
It is discarded
Semicolon endings, not line breaks, tell the C# compiler where a statement stops. That is why one long statement can be spread across several lines of a file.
Q 14Which pair of symbols encloses a block of code in C#, such as the body of a class or method?
Curly braces
Curly braces signal both a block of code and a new scope. A variable declared between a pair stops existing at the closing one, so referring to it afterwards is an error.
Q 15C# treats the names total and Total as two different identifiers; what is this trait of a language called?
Case sensitivity
Case sensitivity applies to every C# identifier. By convention, classes and methods take PascalCase names, while local variables and method arguments are written in camelCase.
Q 16Which C# keyword, written at the top of a file before a name such as System, saves typing full type names?
using
The using directive lets code say Console in place of System.Console. The same keyword has a second job: it begins a statement that closes files and similar objects automatically when a block ends.
Q 17Which C# keyword tells the compiler to work out a local variable's type from the value assigned to it?
var
The var keyword still produces a strongly typed variable, because the compiler fills in the type. It is required for anonymous types, which have no name a programmer could write.
Q 18Which C# loop keyword visits every element of a collection in turn without needing an index variable?
foreach
The foreach statement runs its body once for each element, and skips it entirely when the collection is empty. It works on arrays, lists and any other type that can be enumerated.
Q 19Which C# keyword is written as the return type of a method that gives no value back to its caller?
void
The void keyword tells callers there is no result to use. C# refuses to let a variable be declared with it, since there would be nothing to store.
Q 20In a C# try statement, which block runs whether or not an exception was thrown, making it ideal for cleanup?
finally
The finally block runs whenever control leaves the try block, however it leaves. Programmers put code there to close files and tidy up whatever else the try block had opened.
It is discarded, because converting a double to an integer type rounds toward zero. So 9.99 becomes 9, and -9.99 becomes -9 rather than -10.
Q 24Which int method turns text into a number and returns false, rather than throwing, when the text is invalid?
TryParse
TryParse is like the plain Parse method, except that it reports failure through its return value. The converted number comes back separately, through a second argument.
Q 25Which exception does int.Parse throw in C# when handed text such as hello that is not a valid number?
FormatException
FormatException signals text in the wrong shape, such as letters where digits belong. A number too large to fit in an int triggers a different error, OverflowException.
Q 26In C#, the keyword int is simply an alias for which .NET structure in the System namespace?
Int32
Int32 is named for its size in bits, which caps it at 2,147,483,647. The keyword and the .NET name are interchangeable, so either one can declare a variable.
Q 27Which C# keyword makes integer arithmetic throw an OverflowException instead of silently wrapping round?
checked
The checked keyword is needed because C# integer arithmetic is unchecked by default. Bits that do not fit are simply thrown away, so adding one to the maximum value wraps to the minimum.
Q 28Which method, which every C# type inherits from System.Object, turns a value such as 42 into text?
ToString
ToString is shared by every type because all of them, even plain integers, descend from System.Object. A class that does not supply its own version gets one that merely returns the type's full name.
Q 29What name is given to the C# operator written ??, which returns its right-hand value only when the left has none?
Null-coalescing
Null-coalescing saves writing an if statement: the expression gives its left side unless that is null, and then gives its right. The right-hand side is not even evaluated when the left has a value.
Q 30Which symbol, added after a C# value type such as int, lets a variable of that type also hold null?
A question mark
A question mark turns int into int?, shorthand for Nullable<int>. The variable can then hold null as well as every ordinary int value, and null is where it starts by default.