Control variable scope and logic using code blocks in C#


Use code blocks with more confidence, understanding how they impact the visibility and accessibility of both higher and lower-level constructs in your code.

In this module, you will:

  • Understand the impact of declaring and initializing variables inside and outside of code blocks.
  • Remove code blocks in if statements when there's only one line of code in the body of the code block to improve readability.
  • Identify namespaces, classes, and methods in your code.
  • Understand how moving methods into new classes, and classes into new namespaces impacts the visibility of the code.
  • Understand the use of the using statement to instruct the compiler where to look for classes referenced in your code.


  • Experience declaring and initializing variable values
  • Experience with the if-elseif-else statement
  • Experience calling methods of classes in the .NET Class Library