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

How C# compiles and runs on CLR - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CLR Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this C# code snippet?
Consider this simple C# program compiled to run on the CLR. What will it print when executed?
C Sharp (C#)
using System;
class Program {
    static void Main() {
        int x = 5;
        int y = 10;
        Console.WriteLine($"Sum is: {x + y}");
    }
}
ASum is: 15
BSum is: 510
CSum is: 5 + 10
DCompilation error
Attempts:
2 left
💡 Hint
Remember that + operator adds integers, not concatenates strings here.
🧠 Conceptual
intermediate
1:30remaining
What does the C# compiler produce before running on CLR?
When you compile a C# program, what is the immediate output that the CLR executes?
ANative machine code specific to the CPU
BCommon Intermediate Language (CIL) bytecode
CPlain text source code
DAssembly language code
Attempts:
2 left
💡 Hint
Think about what the CLR understands and runs.
🔧 Debug
advanced
2:00remaining
What error does this C# code cause when run on CLR?
Examine this code and identify the runtime error it will cause when executed on CLR.
C Sharp (C#)
using System;
class Program {
    static void Main() {
        int[] numbers = new int[3];
        numbers[3] = 10;
        Console.WriteLine(numbers[3]);
    }
}
ASyntaxError
BNullReferenceException
CIndexOutOfRangeException
DNo error, prints 10
Attempts:
2 left
💡 Hint
Array indices start at 0 and go up to length-1.
📝 Syntax
advanced
2:30remaining
Which option correctly shows how C# code is compiled and run on CLR?
Select the correct sequence describing how C# code is processed to run on CLR.
AC# source code → Native machine code → CLR executes
BC# source code → CLR directly executes source code
CC# source code → Assembly code → CLR executes assembly
DC# source code → CIL bytecode → CLR's JIT compiler → Native machine code → Execution
Attempts:
2 left
💡 Hint
Remember the role of JIT compiler in CLR.
🚀 Application
expert
3:00remaining
How does the CLR improve cross-platform compatibility for C# programs?
Why does compiling C# to CIL bytecode and running on CLR help C# programs run on different operating systems and CPUs?
ABecause CLR includes a Just-In-Time compiler that converts CIL to native code specific to the current machine
BBecause CIL bytecode is machine code for all CPUs
CBecause C# source code is interpreted directly by CLR without compilation
DBecause CLR translates C# code to Java bytecode for cross-platform support
Attempts:
2 left
💡 Hint
Think about how the same compiled code can run on different machines.