Namespaces का परिचय
एक namespace एक surname जैसा है जो Sam नाम के दो लोगों को अलग रखता है। यह संबंधित code के टुकड़ों को group करता है ताकि कई लोगों के साथ code लिखने पर नाम न टकराएं।
In this page:
Syntax
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
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));
}
}
}
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. #}
आम गलतियां
using System;directive भूल जाना और फिर namespace के बिनाConsoleलिखना (जब तक implicit usings enabled न हों)।- किसी दूसरे namespace की class को बिना
usingया पूरे नाम के उपयोग करना, 'type or namespace not found' error का कारण बनते हुए। - एक ही namespace में दो अलग types को एक जैसा नाम देना, जो एक compile error है।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: