Thursday, June 24, 2004

VJs Tip Of The Day - June 24th 2004

Call to Static Methods

You cannot call static method of a class using the object of the class*... You would have to call it using the Class name itself..
eg.You cannot call base class's static method using base.StaticMethod(); that shall result into an error...

the way you do it is:
//Class having Static Method
public class MyClass
{
public static string StaticMethod()
{
return "Vishal_Joshi@MVPs.org";
}
}

//Class using Static Method
public class ClientClass
{
public string GetHelpLineEmailId()
{
return MyClass.StaticMethod();
}
}

* This is applicable only to C# in case of VB.Net you can access static methods even using the object of the class... (This is what happens to a C# fan.... Thanks to Jacob Cynamon, MS and Kathleen Dollard, MVP for reminding... )

No comments: