Manage and share your stuff. Sign up for FREE!
www.meestuf.com
-----------------------------------------------------------------------------------------
C# 1 – Hello World
C# 2 – Variables
C# 3 - Variable Scope
C# 4 - What If?
C# 5 - What If? Or, Else ?
C# 6 - What If? Or, Else If....?
C# 7 - Switch statement
C# 8 - For loop statement
C# 9 - while-loop statement
C# 10 - do-while-loop statement
C# 11 - Arrays
C# 12 - Multidimensional Arrays - Multiplication Table
C# 13 - Collections - Todo List
C# 14 - Find the largest value in an array
C# 15 - Selection sort
C# 16 - Insertion Sort
C# 17 - Bubble Sort
-----------------------------------------------------------------------------------------
Manage and share your stuff. Sign up for FREE!
www.meestuf.com
Showing posts with label Variable Scope. Show all posts
Showing posts with label Variable Scope. Show all posts
Tuesday, January 8, 2013
Tuesday, September 6, 2011
C# 3 - Variable Scope
1. Create a new console project.
2. Modify Program.cs with the following code.
3. Press F5 to run.
4. Thank you.
2. Modify Program.cs with the following code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSharpEpisode3
{
class Program
{
static void Main(string[] args)
{
VariableExample variableExample = new VariableExample();
Console.WriteLine(variableExample.GlobaVariable);
variableExample.VariableTest();
Console.WriteLine("Press
any key to continue.....");
Console.ReadLine();
}
}
class VariableExample
{
public string
GlobaVariable = "I'm a global variable";
//available both inside and outside this class
private string
PrivateVariable = "I'm a private variable
within VariableExample class"; //available
only inside this class
public void
VariableTest()
{
string localVariable = "I'm
a local variable within VariableTest() method"; //available only within this method VariableTest()
Console.WriteLine(localVariable);
Console.WriteLine(PrivateVariable);
}
}
}3. Press F5 to run.
4. Thank you.
Subscribe to:
Posts (Atom)
