SlideShare a Scribd company logo
C# Tutorial
Part 3 :
Namespaces
www.sirykt.blogspot.com
• Namespaces allow you to create a system to
organize your code.
• A good way to organize your namespaces is via a
hierarchical system.
• You put the more general names at the top of the
hierarchy and get more specific as you go down.
• This hierarchical system can be represented by
nested namespaces. By placing code in different
sub-namespaces, you can keep your code organized.
• A namespace is designed for providing a way to keep one set of names
separate from another.
• The class names declared in one namespace does not conflict with the same
class names declared in another.
• Defining a Namespace
• A namespace definition begins with the keyword namespace followed by the
namespace name as follows:
• namespace namespace_name
• {
• // code declarations
• }
• To call the namespace-enabled version of either function or variable,
prepend the namespace name as follows:
• namespace_name.item_name;
• Namespaces in C# are used to organize too many classes so that it can be easy to
handle the application.
• In a simple C# program, we use System.Console where System is the namespace and
Console is the class.
• To access the class of a namespace, we need to use namespacename.classname. We can
use using keyword so that we don't have to use complete name all the time.
• In C#, global namespace is the root namespace. The global::System will always refer
to the namespace "System" of .Net Framework.
• C# namespace example
• Let's see a simple example of namespace which contains one class "Program".
• using System;
• namespace ConsoleApplication1
• { class Program
• { static void Main(string[] args)
• { Console.WriteLine("Hello Namespace!");
• } } }
• Output:
• Hello Namespace!
• C# namespace example: by fully qualified name
• Let's see another example of namespace in C# where one namespace program
accesses another namespace program.
• using System;
• namespace First
• { public class Hello
• { public void sayHello() { Console.WriteLine("Hello First Namespace");
• }} }
• namespace Second
• { public class Hello
• { public void sayHello() { Console.WriteLine("Hello Second Namespace");
• } } }
• public class TestNamespace
• { public static void Main()
• { First.Hello h1 = new First.Hello();
• Second.Hello h2 = new Second.Hello();
• h1.sayHello();
• h2.sayHello();
• } }
• Output:
• Hello First Namespace Hello Second Namespace
• C# namespace example: by using keyword
• Let's see another example of namespace where we are using "using" keyword so that we don't have to
use complete name for accessing a namespace program.
• using System;
• using First;
• using Second;
• namespace First {
• public class Hello
• { public void sayHello()
• { Console.WriteLine("Hello Namespace");
• } } }
• namespace Second
• { public class Welcome
• { public void sayWelcome()
• { Console.WriteLine("Welcome Namespace");
• } } }
• public class TestNamespace
• { public static void Main()
• { Hello h1 = new Hello();
• Welcome w1 = new Welcome();
• h1.sayHello();
• w1.sayWelcome();
• } }
• Output:
• Hello Namespace Welcome Namespace
• namespace arun.CSharp.Namespaces
{
public class Hello
{
public string GetMessage()
{
return "Hello, world";
}}}
• Namespaces are hierarchical, and the name arun.CSharp.Namespaces is actually
shorthand for defining a namespace named arun that contains a namespace named
CSharp that itself contains a namespace named Namespaces, as in:
• namespace arun
{
namespace CSharp
{
namespace Namespaces
{....}
}}
SIRYKT
Sharing Knowledge is Learning
For more updates
For more visit our website www.sirykt.blogspot.com

More Related Content

Similar to 3namespace in c#

1using in c#
1using in c#1using in c#
1using in c#
Sireesh K
 
Namespace--defining same identifiers again
Namespace--defining same identifiers againNamespace--defining same identifiers again
Namespace--defining same identifiers again
Ajay Chimmani
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
Sireesh K
 
VP-303 lecture#9.pptx
VP-303 lecture#9.pptxVP-303 lecture#9.pptx
VP-303 lecture#9.pptx
Syed Ejaz
 
Net framework
Net frameworkNet framework
Net framework
Abhishek Mukherjee
 
Learn c sharp at amc square learning
Learn c sharp at amc square learningLearn c sharp at amc square learning
Learn c sharp at amc square learning
ASIT Education
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
Jannat Ruma
 
Namespace1
Namespace1Namespace1
Namespace1
zindadili
 
Building .NET Core tools using the Roslyn API by Arthur Tabatchnic at .Net fo...
Building .NET Core tools using the Roslyn API by Arthur Tabatchnic at .Net fo...Building .NET Core tools using the Roslyn API by Arthur Tabatchnic at .Net fo...
Building .NET Core tools using the Roslyn API by Arthur Tabatchnic at .Net fo...
DevClub_lv
 
Learning from "Effective Scala"
Learning from "Effective Scala"Learning from "Effective Scala"
Learning from "Effective Scala"
Kazuhiro Sera
 
UNIT-IV WT web technology for 1st year cs
UNIT-IV WT web technology for 1st year csUNIT-IV WT web technology for 1st year cs
UNIT-IV WT web technology for 1st year cs
javed75
 
C# Class Introduction.pptx
C# Class Introduction.pptxC# Class Introduction.pptx
C# Class Introduction.pptx
Arafat Bin Reza
 
Structure of a C# Program
Structure of a C# ProgramStructure of a C# Program
Structure of a C# Program
Ali Hassan
 
Csharp introduction
Csharp introductionCsharp introduction
Csharp introduction
Sireesh K
 
Learn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square LearningLearn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square Learning
ASIT Education
 
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
yazad dumasia
 

Similar to 3namespace in c# (20)

1using in c#
1using in c#1using in c#
1using in c#
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
Namespace--defining same identifiers again
Namespace--defining same identifiers againNamespace--defining same identifiers again
Namespace--defining same identifiers again
 
Namespace
NamespaceNamespace
Namespace
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
 
VP-303 lecture#9.pptx
VP-303 lecture#9.pptxVP-303 lecture#9.pptx
VP-303 lecture#9.pptx
 
Net framework
Net frameworkNet framework
Net framework
 
Intro to .NET and Core C#
Intro to .NET and Core C#Intro to .NET and Core C#
Intro to .NET and Core C#
 
Learn c sharp at amc square learning
Learn c sharp at amc square learningLearn c sharp at amc square learning
Learn c sharp at amc square learning
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
 
Namespace1
Namespace1Namespace1
Namespace1
 
Building .NET Core tools using the Roslyn API by Arthur Tabatchnic at .Net fo...
Building .NET Core tools using the Roslyn API by Arthur Tabatchnic at .Net fo...Building .NET Core tools using the Roslyn API by Arthur Tabatchnic at .Net fo...
Building .NET Core tools using the Roslyn API by Arthur Tabatchnic at .Net fo...
 
Learning from "Effective Scala"
Learning from "Effective Scala"Learning from "Effective Scala"
Learning from "Effective Scala"
 
UNIT-IV WT web technology for 1st year cs
UNIT-IV WT web technology for 1st year csUNIT-IV WT web technology for 1st year cs
UNIT-IV WT web technology for 1st year cs
 
C# Class Introduction.pptx
C# Class Introduction.pptxC# Class Introduction.pptx
C# Class Introduction.pptx
 
Structure of a C# Program
Structure of a C# ProgramStructure of a C# Program
Structure of a C# Program
 
Csharp introduction
Csharp introductionCsharp introduction
Csharp introduction
 
Learn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square LearningLearn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square Learning
 
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
 

More from Sireesh K

Cn10
Cn10Cn10
Cn10
Sireesh K
 
chanakya neeti
chanakya neetichanakya neeti
chanakya neeti
Sireesh K
 
chanakya neeti
chanakya neetichanakya neeti
chanakya neeti
Sireesh K
 
What is mvc
What is mvcWhat is mvc
What is mvc
Sireesh K
 
31c
31c31c
31cs
31cs31cs
31cs
Sireesh K
 
45c
45c45c
44c
44c44c
43c
43c43c
42c
42c42c
41c
41c41c
40c
40c40c
39c
39c39c
38c
38c38c
37c
37c37c
35c
35c35c
34c
34c34c
33c
33c33c
30c
30c30c
29c
29c29c

More from Sireesh K (20)

Cn10
Cn10Cn10
Cn10
 
chanakya neeti
chanakya neetichanakya neeti
chanakya neeti
 
chanakya neeti
chanakya neetichanakya neeti
chanakya neeti
 
What is mvc
What is mvcWhat is mvc
What is mvc
 
31c
31c31c
31c
 
31cs
31cs31cs
31cs
 
45c
45c45c
45c
 
44c
44c44c
44c
 
43c
43c43c
43c
 
42c
42c42c
42c
 
41c
41c41c
41c
 
40c
40c40c
40c
 
39c
39c39c
39c
 
38c
38c38c
38c
 
37c
37c37c
37c
 
35c
35c35c
35c
 
34c
34c34c
34c
 
33c
33c33c
33c
 
30c
30c30c
30c
 
29c
29c29c
29c
 

Recently uploaded

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 

Recently uploaded (20)

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 

3namespace in c#

  • 1. C# Tutorial Part 3 : Namespaces www.sirykt.blogspot.com
  • 2. • Namespaces allow you to create a system to organize your code. • A good way to organize your namespaces is via a hierarchical system. • You put the more general names at the top of the hierarchy and get more specific as you go down. • This hierarchical system can be represented by nested namespaces. By placing code in different sub-namespaces, you can keep your code organized.
  • 3. • A namespace is designed for providing a way to keep one set of names separate from another. • The class names declared in one namespace does not conflict with the same class names declared in another. • Defining a Namespace • A namespace definition begins with the keyword namespace followed by the namespace name as follows: • namespace namespace_name • { • // code declarations • } • To call the namespace-enabled version of either function or variable, prepend the namespace name as follows: • namespace_name.item_name;
  • 4. • Namespaces in C# are used to organize too many classes so that it can be easy to handle the application. • In a simple C# program, we use System.Console where System is the namespace and Console is the class. • To access the class of a namespace, we need to use namespacename.classname. We can use using keyword so that we don't have to use complete name all the time. • In C#, global namespace is the root namespace. The global::System will always refer to the namespace "System" of .Net Framework. • C# namespace example • Let's see a simple example of namespace which contains one class "Program". • using System; • namespace ConsoleApplication1 • { class Program • { static void Main(string[] args) • { Console.WriteLine("Hello Namespace!"); • } } } • Output: • Hello Namespace!
  • 5. • C# namespace example: by fully qualified name • Let's see another example of namespace in C# where one namespace program accesses another namespace program. • using System; • namespace First • { public class Hello • { public void sayHello() { Console.WriteLine("Hello First Namespace"); • }} } • namespace Second • { public class Hello • { public void sayHello() { Console.WriteLine("Hello Second Namespace"); • } } } • public class TestNamespace • { public static void Main() • { First.Hello h1 = new First.Hello(); • Second.Hello h2 = new Second.Hello(); • h1.sayHello(); • h2.sayHello(); • } } • Output: • Hello First Namespace Hello Second Namespace
  • 6. • C# namespace example: by using keyword • Let's see another example of namespace where we are using "using" keyword so that we don't have to use complete name for accessing a namespace program. • using System; • using First; • using Second; • namespace First { • public class Hello • { public void sayHello() • { Console.WriteLine("Hello Namespace"); • } } } • namespace Second • { public class Welcome • { public void sayWelcome() • { Console.WriteLine("Welcome Namespace"); • } } } • public class TestNamespace • { public static void Main() • { Hello h1 = new Hello(); • Welcome w1 = new Welcome(); • h1.sayHello(); • w1.sayWelcome(); • } } • Output: • Hello Namespace Welcome Namespace
  • 7. • namespace arun.CSharp.Namespaces { public class Hello { public string GetMessage() { return "Hello, world"; }}} • Namespaces are hierarchical, and the name arun.CSharp.Namespaces is actually shorthand for defining a namespace named arun that contains a namespace named CSharp that itself contains a namespace named Namespaces, as in: • namespace arun { namespace CSharp { namespace Namespaces {....} }}
  • 9. For more updates For more visit our website www.sirykt.blogspot.com