0
0
C Sharp (C#)programming~20 mins

What is C# - Practice Questions & Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
C# Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the primary use of C#?

C# is a programming language. What is it mainly used for?

ABuilding Windows desktop applications and web services
BCreating databases and managing data with SQL
CDesigning website layouts with HTML and CSS
DWriting scripts for Linux shell commands
Attempts:
2 left
💡 Hint

Think about what kind of programs you can build with C# on Windows.

Predict Output
intermediate
2:00remaining
What is the output of this C# code?

Look at this C# program. What will it print?

C Sharp (C#)
using System;
class Program {
  static void Main() {
    int x = 5;
    int y = 3;
    Console.WriteLine(x + y);
  }
}
A5 + 3
B53
CError: Cannot add integers
D8
Attempts:
2 left
💡 Hint

Adding two numbers returns their sum.

🔧 Debug
advanced
2:00remaining
What error does this C# code produce?

What error will this code cause when run?

C Sharp (C#)
using System;
class Program {
  static void Main() {
    int number = "10";
    Console.WriteLine(number);
  }
}
AOutput: 10
BRuntime error: NullReferenceException
CCompile-time error: Cannot convert string to int
DCompile-time error: Missing semicolon
Attempts:
2 left
💡 Hint

Check the type assigned to an integer variable.

📝 Syntax
advanced
2:00remaining
Which option correctly declares a method in C#?

Choose the correct way to declare a method that returns an integer and takes no parameters.

Aint GetNumber() { return 5; }
BGetNumber() int { return 5; }
Cint GetNumber { return 5; }
Dint GetNumber() => { 5; }
Attempts:
2 left
💡 Hint

Remember the order: return type, method name, parentheses, braces.

🚀 Application
expert
2:00remaining
What is the value of 'result' after running this C# code?

Consider this code snippet. What is the value of result after execution?

C Sharp (C#)
using System;
class Program {
  static int Multiply(int a, int b = 2) {
    return a * b;
  }
  static void Main() {
    int result = Multiply(3);
    Console.WriteLine(result);
  }
}
A3
B6
C5
DError: Missing argument for parameter 'b'
Attempts:
2 left
💡 Hint

Check the default value of parameter b.