.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

What is the difference between Variable block scope and Class block scope

Posted By:Hiren Soni       Posted Date: August 04, 2010    Points: 10    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

difference between variable block scope and class block scope through the example
 

its better that i will explain you with an example

 

    public partial class Form1 : Form

    {

       int i;

        public Form1()

        {

            InitializeComponent();

            i = 10;

            // when we access i , it will be accessible, because it is in

            // class scope variable, it will be alive till the life of

            // object.

 

            int j = 10;

            // here j scope is within the block( between this { }) only

            // whenver block is completer it will not be acceccese outsite(see form1_load event).

            // it will not be more alive.

        }

 

 

        private void Form1_Load(object sender, EventArgs e)

        {

            i = 20;

 

            //j =20;

            // when we write statement j=20, it will give as error

            // because there is no variable named "j"

 

        }

 

}

 



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend