how to call static
method inside non static
method in c#
?
Interviewer gave me scenario :
class class1
{
pub
A normal practice is to call static method with class name.
See: Static Classes and Static Class Members (C# Programming Guide)
The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created.
So your call would be like:
class1.method1();
But it is not necessary
You can call the static method without class name like:
method1();
But you can only do that inside the class which holds that static method, you can't call static method without class name outside of that class.