Hi All - my first post here - pls dont shoot me :D
Since static functions can access only static variables, how is it that we can use non-static variables inside Main() which is also declared as - public static void Main(string[] args) ?
ex - public static void Main(string[] args)
{
int i; // how can this be used ? its not a static variable !
//...........etc...
}
Loading

Mahesh ChandRank #1 · 393.3K reputationPosted Jan 17, 2009, 2:08 AM EST
You can use non static variables in a static function.
upendra Girish5 reputationPosted Jan 17, 2009, 2:31 AM EST
Please clarify.
Ryan AlfordRank #1,411 · 1.2K reputationPosted Jan 17, 2009, 11:36 AM EST
upendra Girish5 reputationPosted Jan 17, 2009, 5:54 PM EST
Oh ! So for ex -
static int AccDet()
{
int i=7; // then this is ok right ? ..........I can use any var - static or not - as long as I declare it within the scope a static function.
//......................
}
But there would be a problem if -
class MyClass
{
int i;
static void AccDet()
{
i++; // Wrong - coz I can't access a non-static var that is declared outside a static function ?
}
}
Is this right, Ryan ?
BTW thanks for the reply :)