C# Namespace with real life example - GTech eAcademy






Watch Full Explanation of C# Namespace on our YouTube channel  


C sharp namespace with real life example - GTech eAcademy

Discussion points

1) What is namespace in C#?
2) Basic syntax of namespace
3) Understand namespace with examples
4) Naming convention
5) Purpose of using statement
6) Interview Questions

What is namespace in c#?

Formal Definition
A namespace is designed 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.

Informal Definition
1) Collection of classes & interfaces
2) Allow reuse of same class name in different contexts
3) Helps in resolving same class name conflicts

Basic syntax of namespace

C# namespace basic syntax - GTech eAcademy
Namesapce: Basic syntax

Naming Convention

1) Try to give name as a folder hierarchy
2) Separate namespace components with periods
E.g. Microsoft.Office.PowerPoint
3) Use PascalCasing
4) DO NOT use underscores, hyphens or any other nonalphanumeric characters
5) DO NOT use abbreviations or contractions as part of identifier names.
6) Consider using plural namespace names where appropriate.
E.g. System.Collections  👍
System.Collection X
Brand names and acronyms are exceptions to this rule.
E.g. System.IO 👍
System.IOs X
7) Avoid writing same class name & its namespace name

Purpose of using statement

1) The using keyword can be used so that the complete name is not required in your class file as shown in below image


Using statement in C sharp namespace - GTech eAcademy
Using statement in namespace

Important interview questions

1) What is the purpose of the namespace?
2) Is namespace required in your program?
3) Can C# program compile without using a namespace in the program?



***********************************************************************************

Our main focus is to provide free e-learning videos related to programming languages.

Comments

Popular posts from this blog

C# Access Modifiers: What Why How | C#.Net Tutorial - GTech eAcademy