How C# programs execute
Writing source code and running a program are separate activities. A compiler checks language rules and translates valid source into compiled output. Running that output can produce results, fail with an exception or produce a result that is legal but not what you intended.
This program follows the statement syntax and calculates the intended total.
Expected output (not executed here):
20From source to execution
For an ordinary managed console project, the SDK builds an assembly containing intermediate language and metadata. The runtime can load that assembly and execute the program, typically compiling methods to native instructions as needed in the usual just-in-time (JIT) model. Other deployment models exist, including ahead-of-time compilation; they are not required for this first chapter. The simple model is source → build → execution → output.
More examples
Suppose the intended task was to count all items in two bins. Subtraction is legal C# here, but it does not meet the stated requirement. A successful build alone cannot establish that the result is correct.
Expected output (not executed here):
4Where this fits
A compiler diagnostic is a message about a potential or definite problem. For example, omitting the semicolon from an ordinary output statement is intentionally invalid. Correct syntax before running the program. A runtime failure occurs when valid compiled code cannot complete some operation during execution. An incorrect result is different again: execution finishes, but the result does not satisfy the requirement.
Common mistake
Do not assume that a program which builds is correct. The compiler cannot infer the intended business requirement from a sentence such as “combine the two bins.” Define expected outputs first, then compare actual behavior with those expectations. Likewise, do not report an expected result as a test observation when the program has not been run.
Try it yourself
Classify three hypothetical outcomes: a missing semicolon, a program that stops with an exception while running, and a successful program that subtracts when it should add. Explain which stage needs investigation.
Continue with Selecting and checking the SDK. The example source is for an ordinary .NET 10 console project; ByteMind C# execution is not established.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
How C# programs execute — knowledge check
Review the concept before moving on.
When a missing semicolon prevents building, what kind of problem is it?
A program adds instead of multiplying and exits normally. What does this show?
What is typically stored in a managed assembly?
What is the purpose of comparing output with an expected result?