0% found this document useful (0 votes)
9 views6 pages

07 Name Space

The document discusses the concept of namespaces in programming, particularly in C#. It explains how namespaces help avoid name collisions and logically group related classes, using examples of different namespaces and their classes. It also outlines the scope of using directives and their placement within source code files.

Uploaded by

ketkiacharya.net
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

07 Name Space

The document discusses the concept of namespaces in programming, particularly in C#. It explains how namespaces help avoid name collisions and logically group related classes, using examples of different namespaces and their classes. It also outlines the scope of using directives and their placement within source code files.

Uploaded by

ketkiacharya.net
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

http://www.vidyanidhi.

com/
[email protected]

Ketki Acharya
From: SM VITA ATC of
CDAC
9769201036
[email protected]
om

USM’s Shriram Mantri Vidyanidhi Info Tech Academy


Name space
• In all code of console application we see 1st line
• using System
• This is name space having all classes related to input out put.
• In Visual studio open Object explorer, under mscorlib node
you have {}System. within this look for Console class.
• See diagram in next slide

USM’s Shriram Mantri Vidyanidhi Info Tech Academy


USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Name space to avoid name collision
namespace CADbda
namespace CADac {
{ class students
class students {
{ public void dbdaresult()
public void dacresult() {
{ Console.WriteLine("Result of dbda students");
Console.WriteLine("Result of DAC students"); }
} }
}

using System;
• In this example I have 2 name
space CADac andCADbda both
namespace ConsoleApplicationdemo
{ has classs students.
class Program
{ • Due to namespace there is no
static void Main(string[] args) name collision
{
• We can easily use both class
CADac.students s1 = new CADac.students();
CADbda.students s2 = new CADbda.students();
s1dacresult(); because they both are in
}
s2.dbdaresult();
different name space
}
}
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Namespace to logically grouping of data
namespace CADac namespace CAStaff
{ {
class Students class Employee
{ {
public void dacresult() public void paysal()
{ Console.WriteLine("Result of DAC students"); { Console.WriteLine("salary given to stadd");
} }
} }
class Reportcard class Address
{ //some code { //some code
} }
} class visitingfaculty
using System;
{ //some code
using CADac; }
using CAStaff; }
namespace ConsoleApplicationdemo You can see in this example all Dac related class are in namespace CADac
{ name space
class Program And all staff related class are in CAStaff name space. So name space help us
to logically grouping of related classes. In entry point class we have added
{ namespace CADac, , CAStaff
static void Main(string[] args)
{ Students s1 = new Students(); In Dot Net frame work all class realtered to file handling is in namespace
System.io;
s1.dacresult();
Reportcard r1 = new Reportcard();
Employee e1 = new Employee();
e1.paysal();
Address a1 = new Address();
}
}
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
using static System.Console;
class Program { static void Main()
{ WriteLine(“hello”);
}
}
the scope of a using directive is limited to the file in which it
appears.
The using directive can appear:
•At the beginning of a source code file, before any namespace or
type definitions.
•In any namespace, but before any namespace or types declared
in this namespace.
USM’s Shriram Mantri Vidyanidhi Info Tech Academy

You might also like