Method Syntax In Hindi

Method Syntax In Hindi

सी# प्रोग्रामिंग लैंग्वेज में, मेथड सिंटैक्स अन्य ऑब्जेक्ट-ओरिएंटेड प्रोग्राम लैंग्वेज के जैसा ही फीचर्स है, लेकिन सी# प्रोग्रामिंग में क्लास मेथड्स को डिफाइन करने के लिए कुछ बेसिक रूल्स एंड रेगुलेशन होते हैं।

Method Syntax In Hindi

So let’s get to know more about method syntax features in C# programming.

Defining Method in C# Programming.

सी# प्रोग्रामिंग लैंग्वेज में मेथड सिंटेक्स को निचे दिए गए स्ट्रक्चर के साथ डिफाइन किया जा सकता है.

returnType MethodName(parameter1Type parameter1Name, parameter2Type parameter2Name)

{

    // C# program Method body

    return value;  // it set return value for program

}

Example of method in class in C# program.

using System;

class TestClass

{

    // Delare Method with a return data type

    public int mulinteger(int p, int q)

    {

        return p * q;

    }

    // Declare Method without a return type (void method)

    public void PrintMessage(string textmessage)

    {

        Console.WriteLine(textmessage);

    }

}

class Program

{

    static void Main(string[] args)

    {

        TestClass testClass = new TestClass();

        // It Calling the multiply integer method

        int multiply = testClass.mulinteger(4, 3);

        Console.WriteLine(“\n the multiply is – ” + multiply);  // the result is – 12

        // It Calling the Print textMessage method

        testClass.PrintMessage(“\n Hi, Vcanhelpsu Welcome To C#!”);  // the result is – Hi, Vcanhelpsu Welcome To C#!

    }

}

Method return types in C# program.

सी# प्रोग्रामिंग लैंग्वेज में क्लास प्रोग्राम मेथड के मल्टीप्ल रिटर्न टाइप हो सकते हैं, यदि प्रोग्राम में कोई रिटर्न डाटा टाइप है, या प्रोग्राम रिटर्न डाटा टाइप नहीं है.

  • Void Return Data Type – यदि सी# प्रोग्राम लैंग्वेज में कोई रिटर्न डाटा टाइप नहीं है, तो यह मेथड कुछ वैल्यू यानि वोयड डाटा टाइप वैल्यू को रिटर्न नहीं करती है।
  • Other C# Program Return Data Types – इसमें आप सी# प्रोग्राम में int, string, double, आदि जैसे डाटा टाइप से किसी भी डेटा टाइप वैल्यू को प्रोग्राम के अंत में रिटर्न कर सकते हैं।

Example of a method returning value in C# program.

public int Mode(int p, int q)

{

return p %q;

}

Calling a method in C# program.

सी# प्रोग्राम में मेथड को कॉल करने के लिए, आप डिफाइन क्लास के इंस्टेंस (यदि क्लास मेथड स्टैटिक नहीं है) या क्लास नाम (यदि क्लास मेथड स्टैटिक है) मेथड का उपयोग करते हैं।

Calling an instance method in C# program.

TestClass testClass = new TestClass();

testClass.PrintMessage(“This is the instance class method example”);

Calling static class method in C# program (without instance).

class SquareRoot

{

    public static int Square(int p)

    {

        return p * p;

    }

}

class Program

{

    static void Main(string[] args)

    {

        int output = SquareRoot.Square(7);

        Console.WriteLine(output);  // The result is – 49

    }

}

Method overloading in C# program.

सी# प्रोग्रामिंग मेथड ओवरलोडिंग को सपोर्ट करता है, जहाँ आप किसी क्लास प्रोग्राम में एक ही नाम लेकिन अलग-अलग क्लास पैरामीटर आर्गुमेंट वेरिएबल वाली कई अलग अलग मेथड को डिस्प्ले कर सकते हैं।

class Calculate

{

    public int total(int p, int q)

    {

        return p + q;

    }

    public double total(double p, double q)

    {

        return p + q;

    }

    public string total(string p, string q)

    {

        return p + q;

    }

}

C# Programming Method Modifiers.

आप सी# प्रोग्रामिंग मेथड के एक्सेस लेवल को इंडीकेट करने के लिए मेथड मॉडिफायर का उपयोग कर सकते हैं.

जैसे,

  • public – पब्लिक सी# प्रोग्रामिंग मेथड को मौजूदा प्रोग्राम से कहीं से भी एक्सेस या कॉल किया जा सकता है।
  • private – प्राइवेट सी# प्रोग्रामिंग मेथड को केवल क्लास के अंदर या डिफाइन क्लास मेंबर के द्वारा ही एक्सेस किया जा सकता है।
  • protected – प्रोटेक्टेड सी# प्रोग्रामिंग मेथड को क्लास और व्युत्पन्न क्लास के अंदर से ही एक्सेस किया जा सकता है।
  • static – सी# प्रोग्रामिंग मेथड क्लास से ही रिलेटेड होते है, ये इंस्टेंस से नहीं है।

public void PrintMessage()  // public method Can be accessed anywhere in program

{

    Console.WriteLine(“This is a public class method”);

}

private void SecureMethod()  // private class method Can only be accessed within this class

{

    Console.WriteLine(” This is a private class method”);

}