Program की संरचना
एक C# program किसी school की तरह organized होता है: namespaces buildings हैं, classes classrooms हैं, और methods अंदर के lessons हैं। चीज़ें कहां जाती हैं यह जानना उन्हें बाद में ढूंढना आसान बनाता है।
In this page:
Syntax
using System;
namespace NamespaceName
{
class ClassName
{
static void Main(string[] args)
{
// statements
}
}
}
Program Structure
एक C# file namespaces, classes, और methods में organized होती है, जिसमें Main program के entry point की तरह काम करता है। Main के अंदर statements ऊपर से नीचे execute होते हैं।
Hello World से ज़्यादा जटिल कुछ भी लिखने से पहले इस structure को समझना ज़रूरी है।
Note:
किसी executable project के entry point के रूप में सिर्फ एक
Main method की अनुमति है।उदाहरण: Program Structure
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Program started");
Greet();
Console.WriteLine("Program finished");
}
static void Greet()
{
Console.WriteLine("Hello from a helper method!");
}
}
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. #}
आम गलतियां
- यह भूल जाना कि किसी program को सिर्फ एक file में
Mainया top-level statements जैसे entry point की ज़रूरत है। - एक से ज़्यादा files में top-level statements रखना, जो एक compile error है।
- nested namespaces, classes या methods में braces को mismatch करना, जो असली गलती से दूर errors देता है।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: