Mega Code Archive

 
Categories / C# / Class Interface
 

Can call a non-static method through an object reference from within a static method

/* C#: The Complete Reference  by Herbert Schildt  Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */ using System; public class MyClass {    // non-static method.    void nonStaticMeth() {       Console.WriteLine("Inside nonStaticMeth().");    }      /* Can call a non-static method through an       object reference from within a static method. */    public static void staticMeth(MyClass ob) {      ob.nonStaticMeth(); // this is OK    }  }