← Back to C# Course | Chapter 5: Methods | Lesson 2 of 6

Parameters कैसे काम करते हैं

Parameters वे blanks हैं जिन्हें method आपसे भरने के लिए कहता है, जैसे किसी pizza place को अपना size और toppings बताना। method आपके जवाबों का उपयोग अपना काम करने के लिए करता है।

In this page:

  1. Parameters
Syntax
csharp
static void MethodName(type parameter1, type parameter2)
{
    // body
}

MethodName(argument1, argument2);

Parameters

Parameters किसी method को अपने caller से input values पाने देते हैं, हर एक एक declared type और नाम के साथ। Arguments default रूप से value types के लिए value से पास होते हैं, यानी method को अपनी खुद की copy मिलती है।

कई parameters declaration और call दोनों में commas से अलग किए जाते हैं।

Note: Parameter names सिर्फ उनका type नहीं, उनका purpose describe करने चाहिए।

उदाहरण: Parameters

markup
using System;

class Program
{
    static void Greet(string name, int times)
    {
        for (int i = 0; i < times; i++)
        {
            Console.WriteLine($"Hello, {name}!");
        }
    }

    static void Main(string[] args)
    {
        Greet("Sam", 3);
    }
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. एक जैसे types होने पर arguments को गलत order में पास करना, जो compile होता है लेकिन गलत results देता है।
  2. यह उम्मीद करना कि कोई method caller का int बदल देगा, जबकि value-type parameters copies हैं।
  3. बहुत कम या ज़्यादा arguments पास करना, जो एक compile error है।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.