SlideShare a Scribd company logo
Learn C# Programming
Interfaces & Namespaces
Eng Teong Cheah
MVP Visual Studio & Development Technologies
Interfaces
Interfaces
An interface is defined as a syntactical contract that all the classes inheriting the
interface should follow. The interface defines the ‘what’ part of the syntactical contract
and the deriving classes define the ‘how’ party of the syntactical contract.
Interfaces defines properties, methods, and events, which are the members of the
interface. Interfaces contain only the declaration of the members. It is the responsibility f
the deriving class to define the members. It often helps in providing a standard structure
that the deriving classes would follow.
Abstract classes to some extent serve the same purpose, however, they are mostly used
when only few methods are to be declared by the base class and the deriving class
implements the functionalities.
Declaring Interfaces
Interfaces are declared using the interface keyword.
It is similar to class declaration.
Interface statements are public by default.
Demo – Interfaces
Namespaces
Namespaces
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;
Demo – Defining a
Namespace
The using Keyword
The using keyword states that the program is using the names in the given
namespace.
For example, we are using the System namespace in our programs.
The class Console is defined there. We just write –
Console.WriteLine ("Hello there");
The using Keyword
We could have written the fully qualified name as -
Console.WriteLine ("Hello there");
You can also avoid prepending of namespaces with the using namespace
directive.
This directive tells the compiler that the subsequent code is making use of names
in the specified namespace.
Demo – The using
keyword
Nested Namespaces
You can define one namespace inside another namespace as follows –
namespace namespace_name1 {
// code declarations
namespace namespace_name2 {
// code declarations
}
}
Demo – Nested
Namespace
Related Content
TutorialsPoint
www.tutorialspoint.com
Thank you

More Related Content

PPTX
Polymorphism and interface in vb.net
PPTX
Java presentation
PPT
Java interface
PDF
What is Interface in Java | How to implement Multiple Inheritance Using Inter...
PPTX
Visual Basic –User Interface- V
PPT
Chapter 9 Interface
PPT
Codings Standards
PPTX
15 interfaces
Polymorphism and interface in vb.net
Java presentation
Java interface
What is Interface in Java | How to implement Multiple Inheritance Using Inter...
Visual Basic –User Interface- V
Chapter 9 Interface
Codings Standards
15 interfaces

What's hot (14)

PDF
Java OOP Programming language (Part 6) - Abstract Class & Interface
PDF
Xamarin: Inheritance and Polymorphism
PDF
What are Generics in Java | Java Generics Tutorial | Edureka
DOCX
Java interface
PPTX
abstract class and interface.Net
DOCX
Mit4021 c# and .net
PPT
Interface in java By Dheeraj Kumar Singh
PPT
Interfaces In Java
PPTX
Interface in java ,multiple inheritance in java, interface implementation
PPTX
Lecture 1 uml with java implementation
PPTX
Java interfaces
DOCX
Bt0074
PPTX
Class Diagram | OOP and Design Patterns by Oum Saokosal
PDF
8 abstract classes and interfaces
Java OOP Programming language (Part 6) - Abstract Class & Interface
Xamarin: Inheritance and Polymorphism
What are Generics in Java | Java Generics Tutorial | Edureka
Java interface
abstract class and interface.Net
Mit4021 c# and .net
Interface in java By Dheeraj Kumar Singh
Interfaces In Java
Interface in java ,multiple inheritance in java, interface implementation
Lecture 1 uml with java implementation
Java interfaces
Bt0074
Class Diagram | OOP and Design Patterns by Oum Saokosal
8 abstract classes and interfaces
Ad

Similar to Learn C# programming - Interfaces & Namespaces (20)

PPT
Namespace
PPTX
VP-303 lecture#9.pptx
PPTX
1using in c#
PPTX
3namespace in c#
PPTX
VB.NET:An introduction to Namespaces in .NET framework
PPTX
Module 12 aggregation, namespaces, and advanced scope
PPTX
Introduction-to-Java-Namespaces.pptx ejb
PDF
Csharp_Chap02
PDF
Namespace--defining same identifiers again
ODP
Namespace inPHP
PPTX
Namespace in C++ Programming Language
PPTX
C# And Data types itrodu ction to C# fucntins
PDF
Learn C# programming - Program Structure & Basic Syntax
PPTX
Namespace1
PPTX
Introduction to C#
PPTX
Object Oriented Programming Using C++: C++ Namespaces.pptx
PDF
Namespace.pdf
DOCX
csharp.docx
PDF
LectureNotes-02-DSA
Namespace
VP-303 lecture#9.pptx
1using in c#
3namespace in c#
VB.NET:An introduction to Namespaces in .NET framework
Module 12 aggregation, namespaces, and advanced scope
Introduction-to-Java-Namespaces.pptx ejb
Csharp_Chap02
Namespace--defining same identifiers again
Namespace inPHP
Namespace in C++ Programming Language
C# And Data types itrodu ction to C# fucntins
Learn C# programming - Program Structure & Basic Syntax
Namespace1
Introduction to C#
Object Oriented Programming Using C++: C++ Namespaces.pptx
Namespace.pdf
csharp.docx
LectureNotes-02-DSA
Ad

More from Eng Teong Cheah (20)

PDF
Modern Cross-Platform Apps with .NET MAUI
PDF
Efficiently Removing Duplicates from a Sorted Array
PDF
Monitoring Models
PDF
Responsible Machine Learning
PDF
Training Optimal Models
PDF
Deploying Models
PDF
Machine Learning Workflows
PDF
Working with Compute
PDF
Working with Data
PDF
Experiments & TrainingModels
PDF
Automated Machine Learning
PDF
Getting Started with Azure Machine Learning
PDF
Hacking Containers - Container Storage
PDF
Hacking Containers - Looking at Cgroups
PDF
Hacking Containers - Linux Containers
PDF
Data Security - Storage Security
PDF
Application Security- App security
PDF
Application Security - Key Vault
PDF
Compute Security - Container Security
PDF
Compute Security - Host Security
Modern Cross-Platform Apps with .NET MAUI
Efficiently Removing Duplicates from a Sorted Array
Monitoring Models
Responsible Machine Learning
Training Optimal Models
Deploying Models
Machine Learning Workflows
Working with Compute
Working with Data
Experiments & TrainingModels
Automated Machine Learning
Getting Started with Azure Machine Learning
Hacking Containers - Container Storage
Hacking Containers - Looking at Cgroups
Hacking Containers - Linux Containers
Data Security - Storage Security
Application Security- App security
Application Security - Key Vault
Compute Security - Container Security
Compute Security - Host Security

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PPTX
Big Data Technologies - Introduction.pptx
PPTX
A Presentation on Artificial Intelligence
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Electronic commerce courselecture one. Pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Empathic Computing: Creating Shared Understanding
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
Machine learning based COVID-19 study performance prediction
Big Data Technologies - Introduction.pptx
A Presentation on Artificial Intelligence
“AI and Expert System Decision Support & Business Intelligence Systems”
Electronic commerce courselecture one. Pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
MYSQL Presentation for SQL database connectivity
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Weekly Chronicles - August'25-Week II
Empathic Computing: Creating Shared Understanding
gpt5_lecture_notes_comprehensive_20250812015547.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Spectral efficient network and resource selection model in 5G networks
Review of recent advances in non-invasive hemoglobin estimation
Network Security Unit 5.pdf for BCA BBA.
Dropbox Q2 2025 Financial Results & Investor Presentation
Advanced methodologies resolving dimensionality complications for autism neur...
Assigned Numbers - 2025 - Bluetooth® Document
Digital-Transformation-Roadmap-for-Companies.pptx
The AUB Centre for AI in Media Proposal.docx

Learn C# programming - Interfaces & Namespaces

  • 1. Learn C# Programming Interfaces & Namespaces Eng Teong Cheah MVP Visual Studio & Development Technologies
  • 3. Interfaces An interface is defined as a syntactical contract that all the classes inheriting the interface should follow. The interface defines the ‘what’ part of the syntactical contract and the deriving classes define the ‘how’ party of the syntactical contract. Interfaces defines properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members. It is the responsibility f the deriving class to define the members. It often helps in providing a standard structure that the deriving classes would follow. Abstract classes to some extent serve the same purpose, however, they are mostly used when only few methods are to be declared by the base class and the deriving class implements the functionalities.
  • 4. Declaring Interfaces Interfaces are declared using the interface keyword. It is similar to class declaration. Interface statements are public by default.
  • 7. Namespaces 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.
  • 8. 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;
  • 9. Demo – Defining a Namespace
  • 10. The using Keyword The using keyword states that the program is using the names in the given namespace. For example, we are using the System namespace in our programs. The class Console is defined there. We just write – Console.WriteLine ("Hello there");
  • 11. The using Keyword We could have written the fully qualified name as - Console.WriteLine ("Hello there"); You can also avoid prepending of namespaces with the using namespace directive. This directive tells the compiler that the subsequent code is making use of names in the specified namespace.
  • 12. Demo – The using keyword
  • 13. Nested Namespaces You can define one namespace inside another namespace as follows – namespace namespace_name1 { // code declarations namespace namespace_name2 { // code declarations } }