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

Program की संरचना

एक C# program किसी school की तरह organized होता है: namespaces buildings हैं, classes classrooms हैं, और methods अंदर के lessons हैं। चीज़ें कहां जाती हैं यह जानना उन्हें बाद में ढूंढना आसान बनाता है।

In this page:

  1. Program Structure
Syntax
csharp
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

markup
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!");
    }
}
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. यह भूल जाना कि किसी program को सिर्फ एक file में Main या top-level statements जैसे entry point की ज़रूरत है।
  2. एक से ज़्यादा files में top-level statements रखना, जो एक compile error है।
  3. nested namespaces, classes या methods में braces को mismatch करना, जो असली गलती से दूर errors देता है।
🔒

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.