Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

In C# how we call a static class method?

user-image
Question added by Atif Jalal , Front-End Web Developer , Brain Plow
Date Posted: 2016/09/01
Pathan Zarrar Khadar Khan
by Pathan Zarrar Khadar Khan , Windows System Administrator , Dyce Tech Pvt Ltd

In C# we does not required  Object of the Static class, we can Call Directly  To  the Method

for Example 

classname.methodname(); 

Sayed Elshayeb
by Sayed Elshayeb , senior analyst programmer , EPL House

with the <class name>.<method name>

Deleted user
by Deleted user

We just need to right the Class Name following by method name

 

Example

 

public static class Rectangle

{

           public static int CalculateArea(int width, int height)

           {

                 return width * height;

           }

}

 

Here to access the method CalculateArea present in class Rectangle we just need to write the following syntax

 

Rectangle.CalculateArea(5,4); 

 

 

 

 

Fahad Anwar
by Fahad Anwar , Senior Application Architect , dubai health authority - governement of dubai - uae

In C# you can call static class methods using below syntax

 

ClassName.MethodName

Muhammad Ghunaim
by Muhammad Ghunaim , Analyst Programmer , Abdul Latif Jameel United Finance Co

Using the class name directly without create an object from it.

 

ClassName.StaticMethodName();

Jafer Sathik SA
by Jafer Sathik SA , Asp .Net Web Developer , Soroof International

We can call the static mehtod Through the ClassName Onwhich the Static method is member.

like MyClass.mystaticmethod();

More Questions Like This