All featured quizzes

C# - Basics

Class inheritance, const vs readonly, StringBuilder, string interpolation, and read-only properties.

Sample Questions

A preview of what's in this quiz. Answer them interactively for instant scoring and full explanations.

What does C# source code compile into before it is run?

1. What does C# source code compile into before it is run?

  • A.Machine code directly
  • B.Intermediate Language (IL)
  • C.Assembly language files
  • D.JavaScript script code
What is the size of an `int` variable in C#?

2. What is the size of an `int` variable in C#?

  • A.16 bits (2 bytes)
  • B.32 bits (4 bytes)
  • C.64 bits (8 bytes)
  • D.8 bits (1 byte)
Which numeric type should be used for financial and monetary calculations in C# to prevent rounding errors?

3. Which numeric type should be used for financial and monetary calculations in C# to prevent rounding errors?

  • A.double
  • B.decimal
  • C.float
  • D.long
Which of the following is a Value Type in C#?

4. Which of the following is a Value Type in C#?

  • A.class
  • B.struct
  • C.string
  • D.interface
Which of the following is correct regarding Value Types vs Reference Types in C#?

5. Which of the following is correct regarding Value Types vs Reference Types in C#?

  • A.Reference types store data directly; Value types store references.
  • B.Value types store data directly (usually on stack); Reference types store memory references pointing to data (on heap).
  • C.Both value and reference types are stored on the stack.
  • D.Reference types are immutable by default; Value types are mutable.
Which component of the .NET runtime compiles IL (Intermediate Language) into native machine code at application startup?

6. Which component of the .NET runtime compiles IL (Intermediate Language) into native machine code at application startup?

  • A.Roslyn compiler
  • B.JIT Compiler
  • C.CLR runtime engine
  • D.Garbage Collector
Which of the following is a Reference Type in C#?

7. Which of the following is a Reference Type in C#?

  • A.struct
  • B.class
  • C.enum
  • D.double
What does CLR stand for, and what is its role in .NET?

8. What does CLR stand for, and what is its role in .NET?

  • A.Common Library Repository: A package directory structure.
  • B.Common Language Runtime: The execution engine managing running .NET applications.
  • C.Class Layout Resolver: A compiler formatting tool.
  • D.Core Link Router: A networking utility.
What is the suffix letter used to define a `decimal` literal value in C#?

9. What is the suffix letter used to define a `decimal` literal value in C#?

  • A.D (for double)
  • B.M
  • C.F (for float)
  • D.L (for long)
What is the default value of an uninitialized boolean variable in class scope in C#?

10. What is the default value of an uninitialized boolean variable in class scope in C#?

  • A.true
  • B.false
  • C.null
  • D.0
What is the purpose of a Constructor in a class?

11. What is the purpose of a Constructor in a class?

  • A.To release memory before object destruction
  • B.To initialize a newly created object's state
  • C.To load namespaces into code files
  • D.To call static class methods
Which access modifier restricts visibility to the defining class only?

12. Which access modifier restricts visibility to the defining class only?

  • A.public
  • B.private
  • C.protected
  • D.internal
What is a Nullable Value Type in C#?

13. What is a Nullable Value Type in C#?

  • A.A reference type that cannot contain null
  • B.A value type wrapper allowing the type to be assigned `null`
  • C.A pointer pointing to null variables
  • D.A class that cannot be instantiated
What is an Auto-Implemented Property in C#?

14. What is an Auto-Implemented Property in C#?

  • A.A property populated automatically from database fields.
  • B.A property declaring concise get/set accessors, letting the compiler generate backing fields.
  • C.A property read-only by default.
  • D.A property that cannot be null.
Which access modifier makes a member visible to the defining class and any subclass deriving from it?

15. Which access modifier makes a member visible to the defining class and any subclass deriving from it?

  • A.private
  • B.protected
  • C.internal
  • D.public
What is the purpose of Namespaces in C#?

16. What is the purpose of Namespaces in C#?

  • A.To compile code files into libraries
  • B.To organize classes and create distinct naming scopes
  • C.To manage memory allocation on heap
  • D.To connect classes to database tables
Which keyword is used to import a namespace into a C# source file?

17. Which keyword is used to import a namespace into a C# source file?

  • A.import
  • B.using
  • C.include
  • D.require
Does C# support static constructors inside classes?

18. Does C# support static constructors inside classes?

  • A.No, constructors must always be instance-specific.
  • B.Yes, static constructors initialize static fields and run once automatically.
  • C.Yes, but they must be called manually using `new`.
  • D.Yes, but only in abstract classes.
How do you create a read-only property in modern C#?

19. How do you create a read-only property in modern C#?

  • A.Mark it with the `readonly` keyword inside the signature: `public readonly int Id { get; set; }`
  • B.Omit the `set` accessor: `public int Id { get; }`
  • C.Make the getter private and omit the setter.
  • D.Declare it as a constant property: `public const int Id { get; set; }`
Which access modifier limits visibility to the current assembly (project dll/exe file) only?

20. Which access modifier limits visibility to the current assembly (project dll/exe file) only?

  • A.protected
  • B.internal
  • C.private
  • D.public

Looking for a different topic? Browse all subjects