Allow me to repeat myself: static members can operate only on static data and call static methods of the
defining class. If you attempt to make use of nonstatic class data or call a nonstatic method of the class within a
static member’s implementation, you’ll receive compile-time errors.
Like any static member, to call Complain(), prefix the name of the defining class:
static void Main(string[] args)
{
Console.WriteLine("***** Fun with Static Methods *****\n");
for(int i =0; i < 5; i++)
Console.WriteLine(Teenager.Complain());
Console.ReadLine();
}
Do'stlaringiz bilan baham: