Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

In C# how we call a static class method?

user-image
Question ajoutée par Atif Jalal , Front-End Web Developer , Brain Plow
Date de publication: 2016/09/01
Pathan Zarrar Khadar Khan
par 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
par Sayed Elshayeb , senior analyst programmer , EPL House

with the <class name>.<method name>

Utilisateur supprimé
par Utilisateur supprimé

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
par 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
par 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
par 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

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?