LogIn
I don't have account.

Practice c-sharp Quizzes

Boost your knowledge of c-sharp with DevBrainiac's interactive quizzes that make learning faster and more effective. Each quiz focuses on real-world concepts, helping you improve accuracy, understand fundamentals and prepare better for technical interviews. Suitable for beginners and professionals alike, our c-sharp quizzes offer a focused, practical approach to mastering the topic.

Explore All c-sharp Quizzes

Learn c-sharp step by step with interactive quizzes designed for beginners and learners revising key concepts. Build a strong foundation with clear, structured practice in c-sharp.
Question 1
Which of the following is true about C#?
1
C# is a statically-typed language
2
C# supports multiple inheritance directly
3
C# does not support garbage collection
4
C# does not support object-oriented programming
5
None of the above
Question 2
What is the default access modifier for a class in C#?
1
Private
2
Internal
3
Protected
4
public
Question 3
Which of the following is NOT a valid C# data type?
1
double
2
real
3
float
4
int
Question 4
What is the output of the following C# code?
int a = 5, b = 2;
double result = a / b;
Console.WriteLine(result);
1
2.0
2
Compilation error
3
2
4
2.5
Question 5
Which of the following statements about C# constructors is true?
1
A constructor must always have a return type
2
A class can have only one constructor
3
A constructor can be called explicitly like a normal method
4
A constructor is automatically called when an object is created
Question 6
What is the keyword used to inherit a class in C#?
1
implements
2
extends
3
inherits
4
: (colon)
Question 7
What is the difference between == and .Equals() in C#?
1
Both are the same and compare object references
2
== compares values, whereas .Equals() compares references
3
== compares references, whereas .Equals() compares values
4
None of the above
Question 8
What will be the output of the following code?
string s1 = "Hello";
string s2 = "Hello";
Console.WriteLine(s1 == s2);
Console.WriteLine(s1.Equals(s2));
1
True True
2
True False
3
False False
4
False True
Question 9
Which of the following statements about C# interfaces is true?
1
An interface can contain constructors
2
An interface can have fields
3
An interface cannot be inherited by another interface
4
An interface can provide default method implementation
Question 10
What is the purpose of the using statement in C#?
1
It imports namespaces
2
It defines scope for disposing objects
3
It handles exceptions
4
Both 1 and 2
Question 11
What is the output of the following C# code?
using System;

class Program
{
    static void Main()
    {
        int x = 10;
        object obj = x;
        int y = (int)obj;
        Console.Write(y);
    }
}
1
NullReferenceException
2
Compilation error
3
10
4
Runtime error
Question 12
What is the correct way to define a nullable integer in C#?
1
int num = nullable;
2
null int num;
3
nullable<int> num = null;
4
int? num = null;
Question 13
Which of the following is true about C# properties?
1
Properties must always have both get and set
2
Properties cannot be read-only
3
Properties are just variables with additional syntax
4
Properties can have different access modifiers for get and set
Question 14
Which keyword is used to prevent a class from being inherited?
1
private
2
abstract
3
static
4
sealed
Question 15
Which of the following correctly implements an interface in C#?
1
interface ITest { void Show(); }
class MyClass { public void Show() { Console.WriteLine("Hello"); } }
2
interface ITest { void Show(); }
class MyClass : ITest { void Show() { Console.WriteLine("Hello"); } }
3
interface ITest { void Show(); }
class MyClass : ITest { public void Show() { Console.WriteLine("Hello"); } }
4
interface ITest { void Show(); }
class MyClass : ITest { protected void Show() { Console.WriteLine("Hello"); } }
Question 16
What will be the output of the following LINQ query?
var numbers = new List<int> { 2, 3, 4, 5 };
var result = numbers.Where(n => n % 2 == 0);
Console.WriteLine(result.Count());
1
3
2
2
3
1
4
4
Question 17
What will happen if you call ToString() on a null object in C#?
1
It throws a NullReferenceException
2
It returns an empty string
3
It returns "null"
4
It depends on the object's type
Question 18
What is the output of the following C# code?
async Task<int> GetNumberAsync() { return 5; }
async Task Main()
{
    Task<int> task = GetNumberAsync();
    Console.WriteLine("Before await");
    int result = await task;
    Console.WriteLine($"Result: {result}");
}
1
Before await
Result: 5
2
Result: 5
Before await
3
Random execution order
4
Compilation error
Question 19
Which of the following statements about Dictionary in C# is true?
1
Keys in a dictionary must be unique
2
A dictionary allows only string keys
3
A dictionary stores elements in a sorted order
4
All of the above
Question 20
What type of inheritance is not supported in C#?
1
Hierarchical Inheritance
2
Multiple Inheritance
3
Multilevel Inheritance
4
Single Inheritance
Question 21
Which of the following is true about abstract classes in C#?
1
Abstract classes can be instantiated.
2
Abstract classes must have at least one abstract method.
3
An abstract class can have concrete methods.
4
Interfaces and abstract classes are the same.
Question 22
Which keyword prevents method overriding in C#?
1
private
2
abstract
3
final
4
sealed
Question 23
Which of the following best describes the .NET framework?
1
A hardware component
2
An operating system
3
A development platform
4
A database management system
Question 24
Which language influenced the development of C# the most?
1
PHP
2
Python
3
C++
4
Java
Question 25
What is the primary runtime used to execute C# programs?
1
Dynamic Link Library (DLL)
2
Java Virtual Machine (JVM)
3
Common Runtime Interface (CRI)
4
Common Language Runtime (CLR)
Question 26
If you receive a 'namespace not found' error, what is the likely cause?
1
Typo in the class name
2
Incorrect file extension
3
Missing 'using' directive
4
Missing semicolon
Question 27
What will be the output of the following code?
int a = 5, b = 2;
Console.WriteLine(a / b);
1
3
2
2
3
2.5
4
Error
Question 28
Which operator has the highest precedence in C#?
1
()
2
*
3
+
4
=
Question 29
What does the ?? operator do in C#?
1
Checks type
2
Performs bitwise OR
3
Performs null-coalescing
4
Checks equality
Question 30
What is the result of this expression: true || false && false?
1
false
2
Error
3
Cannot determine
4
true