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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Hiren SoniRank #694 · 3.5K reputationPosted Jul 25, 2010, 9:25 PM EDT
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"
}
}
Manish TewatiaRank #48 · 31.3K reputationPosted Jul 28, 2010, 3:36 AM EDT
Hiren SoniRank #694 · 3.5K reputationPosted Jul 28, 2010, 4:49 AM EDT