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
upendra GirishPosted Jan 17, 2009, 10:54 PM
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 :)
Ryan AlfordPosted Jan 17, 2009, 4:36 PM
upendra GirishPosted Jan 17, 2009, 7:31 AM
Please clarify.
Mahesh ChandPosted Jan 17, 2009, 7:08 AM
You can use non static variables in a static function.