O'Reilly logo

HoloLens Beginner’s Guide by Jason Odom

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Understanding scope

The scope of a variable is the area or length of code that can be used. In a sense, scope is a variable's lifetime. There are two primary types of scope that we use with regularity in C#:

  • Local scope: These variables are defined within a method or inside the block of a method. Local scope variables defined within a method are released when the method ends. 
  • Class-level scope: All the names defined inside the current class, aside from local names, are said to be local to that class. This means that the class-level variables live as long as the class is active.

Code blocks are generally the means of defining a scope and are marked with curly braces {}:

 public class ScopeExample: MonoBehavior { public int dododododo = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required