Scope
Python Example
x = "global"
def function():
x = "local"
print(x) # prints "local"
function()
print(x) # prints "global"C# Example
using System;
class Program
{
static string x = "global"; // Global scope variable
static void Main(string[] args)
{
string x = "local"; // Local scope variable
Console.WriteLine(x); // prints "local"
}
static void PrintGlobal()
{
Console.WriteLine(x); // prints "global"
}
}
Last updated
Was this helpful?