← Back to C# Course | Chapter 1: Setup & Basics | Lesson 7 of 7

Comments लिखना

Comments खुद और दूसरे readers के लिए notes हैं जिन्हें computer नज़रअंदाज़ करता है, जैसे किसी notebook के margin में doodles। वे समझाते हैं कि code जो करता है वह क्यों करता है।

In this page:

  1. Comments
Syntax
csharp
// single-line comment

/* multi-line
   comment */

/// <summary>
/// XML documentation comment
/// </summary>

Comments

C# // से single-line comments, /* */ से multi-line comments, और /// से XML documentation comments को support करता है जिन्हें tools documentation में बदल सकते हैं।

Comments को compiler नज़रअंदाज़ करता है और यह सिर्फ इंसानों को code समझाने के लिए मौजूद होते हैं। अच्छे comments *क्यों* समझाते हैं, वह नहीं जो code पहले से स्पष्ट करता है।

Note: Visual Studio जैसी IDEs /// summary comments को IntelliSense tooltips के रूप में render करती हैं।

उदाहरण: Comments

markup
using System;

class Program
{
    /// <summary>
    /// Adds two integers together.
    /// </summary>
    static int Add(int a, int b)
    {
        // simple addition, no overflow checking
        return a + b;
    }

    static void Main(string[] args)
    {
        /* Call the helper and print the result */
        Console.WriteLine(Add(2, 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. /* */ comments को nest करने की कोशिश करना, जहां पहला */ पूरा comment खत्म कर देता है।
  2. Python की तरह comments के लिए # का उपयोग करना, जबकि C# // और /* */ उपयोग करता है।
  3. code बदलने के बाद पुराने code का वर्णन करने वाले comments छोड़ देना।
चैप्टर सारांश
  • C# .NET के साथ उपयोग होने वाली एक language है, जिसे आप programs बनाने और चलाने के लिए install करते हैं।
  • dotnet CLI projects बनाता और चलाता है, एक Hello World program से शुरू करते हुए।
  • Program structure, namespaces, और comments आपके code को organize और document करते हैं।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 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.