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

Namespaces का परिचय

एक namespace एक surname जैसा है जो Sam नाम के दो लोगों को अलग रखता है। यह संबंधित code के टुकड़ों को group करता है ताकि कई लोगों के साथ code लिखने पर नाम न टकराएं।

In this page:

  1. Namespaces
Syntax
csharp
namespace Company.Project
{
    class ClassName { }
}

using Company.Project;   // import to use short names

Namespaces

Namespaces संबंधित classes को साथ group करते हैं और libraries के बीच naming collisions रोकते हैं। आप namespace keyword से अपना namespace declare करते हैं, और using से दूसरों को लाते हैं। बड़े C# codebases organized रहने के लिए namespaces पर काफी निर्भर करते हैं।

Note: Namespace names convention के अनुसार Company.Product.Module जैसे dotted, PascalCase pattern का पालन करते हैं।

उदाहरण: Namespaces

markup
using System;

namespace MyApp.Utilities
{
    class MathHelper
    {
        public static int Square(int n) => n * n;
    }
}

namespace MyApp
{
    using MyApp.Utilities;

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(MathHelper.Square(5));
        }
    }
}
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. using System; directive भूल जाना और फिर namespace के बिना Console लिखना (जब तक implicit usings enabled न हों)।
  2. किसी दूसरे namespace की class को बिना using या पूरे नाम के उपयोग करना, 'type or namespace not found' error का कारण बनते हुए।
  3. एक ही namespace में दो अलग types को एक जैसा नाम देना, जो एक compile error है।
🔒

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.