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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Brajesh KumarPosted Feb 24, 2017, 9:17 AM
// 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 KumarPosted Feb 24, 2017, 9:14 AM
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.namespace SampleNamespace{ class SampleClass { }interface SampleInterface { }struct SampleStruct { }enum SampleEnum { a, b }namespace SampleNamespace.Nested{class SampleClass2{ }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:namespace MyCompany.Proj1{ class MyClass{ } }namespace MyCompany.Proj1{ class MyClass1{