Hi,
We use namespaces for grouping the related classes.What Is Means Related classes?
Any One Can You Explain?
Thanks In Advance,
Moulali.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Brajesh KumarRank #678 · 3.5K reputationPosted Feb 24, 2017, 4:17 AM EST
// Namespace Declaration
using System;
// The Namespace
namespace MyNameSpace
{
// Program start class
class MyClass
{
//Functionality
}
}
// Namespace Declaration
using System;
// The Namespaces
namespace MyNameSpace
{
namespace Video
{
// Program start class
class MyVideo
{
//Functionality
//..
}
}
{
// Program start class
class MyAudio
{
//Functionality
public static void play()
//..
}
}
If we call play method in the same namespace then no need to include MynameSpace at the begin e.g. Video.play().
Now implement this by using directive
using MyNameSpace.Video;
using MynameSpace.Audio;
Brajesh KumarRank #678 · 3.5K reputationPosted Feb 24, 2017, 4:14 AM EST
The
namespacekeyword is used to declare a scope that contains a set of related objects. You can use a namespace to organize code elements and to create globally unique types.Remarks
Within a namespace, you can declare one or more of the following types:
another namespace
class
interface
struct
enum
delegate
Whether or not you explicitly declare a namespace in a C# source file, the compiler adds a default namespace. This unnamed namespace, sometimes referred to as the global namespace, is present in every file. Any identifier in the global namespace is available for use in a named namespace.
Namespaces implicitly have public access and this is not modifiable. For a discussion of the access modifiers you can assign to elements in a namespace, see Access Modifiers.
It is possible to define a namespace in two or more declarations. For example, the following example defines two classes as part of the
MyCompanynamespace: