Hello every body
I have a problem, I can't clearly understand that what is the main difference between this two type of block scope
Variable block scope
Class block scope
Please any one explain to me
Thank you....
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Hiren SoniPosted Jul 28, 2010, 8:49 AM
Manish TewatiaPosted Jul 28, 2010, 7:36 AM
Hiren SoniPosted Jul 26, 2010, 1:25 AM
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"
}
}