codecandle logo




 

C# - Functions - Variable Scope


Related: C# Tutorial

Date: 30.04.2011

Variable in C# have a scope within which they are valid. Scope indicates code block-nested code blocks that variable is defined.


namespace NS1
{
class Program
{

static void show()
{
Console.WriteLine(stateName); //ERROR: inaccessable here
}

static void Main(string [] args)
{
string stateName = "nebraska";
show();
Console.WriteLine(stateName); //OK

{
string stateName_2 = "nevada";
Console.WriteLine(stateName_2); //OK
}
Console.WriteLine(stateName_2); //ERROR: inaccessable here
}
}
}

Area: articles

Reference resources: http://msdn.microsoft.com/en-us/library/aa200276%28v=office.11%29.aspx
Tags: C# - variable scope

Catagory layer 1: Programming
Catagory layer 2: Languages

Code layer 1: Languages
Code layer 2: csharp
Code layer 3: C# 1.0
Code layer 4: functions
Code layer 5: variable-scope

Reader layer 1: beginner

Sector layer 1: C# Programmer

Fuzzy layer 1: C# Language Reference
Fuzzy layer 2: C# variable scopes in functions

Nodes: Languages\C# (1)
  • comment icon
  • Comments Section
  • Post your Comment:


Chat section


[ Copy this | Start New | Full Size ]