Comments लिखना
Comments खुद और दूसरे readers के लिए notes हैं जिन्हें computer नज़रअंदाज़ करता है, जैसे किसी notebook के margin में doodles। वे समझाते हैं कि code जो करता है वह क्यों करता है।
In this page:
Syntax
// 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
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));
}
}
Login to try C/C++/Java/PHP code in the editor
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. #}
आम गलतियां
/* */comments को nest करने की कोशिश करना, जहां पहला*/पूरा comment खत्म कर देता है।- Python की तरह comments के लिए
#का उपयोग करना, जबकि C#//और/* */उपयोग करता है। - 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: