ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

In C# how we call a static class method?

user-image
تم إضافة السؤال من قبل Atif Jalal , Front-End Web Developer , Brain Plow
تاريخ النشر: 2016/09/01
Pathan Zarrar Khadar Khan
من قبل 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
من قبل Sayed Elshayeb , senior analyst programmer , EPL House

with the <class name>.<method name>

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
من قبل 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
من قبل 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
من قبل 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();

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟