0% found this document useful (0 votes)
12 views

8 The C# Language Part 7

This document discusses namespaces, assemblies, and inheritance in C#. It explains that namespaces organize types in class libraries and can be nested. Assemblies are physical files that contain compiled code and can contain multiple namespaces. Inheritance allows one class to acquire and extend the functionality of another class, and there are different types of inheritance like single, multilevel, and multiple inheritance. The take home task is to write a C# program implementing multilevel inheritance that takes student details across multiple classes and displays the results.

Uploaded by

sanil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

8 The C# Language Part 7

This document discusses namespaces, assemblies, and inheritance in C#. It explains that namespaces organize types in class libraries and can be nested. Assemblies are physical files that contain compiled code and can contain multiple namespaces. Inheritance allows one class to acquire and extend the functionality of another class, and there are different types of inheritance like single, multilevel, and multiple inheritance. The take home task is to write a C# program implementing multilevel inheritance that takes student details across multiple classes and displays the results.

Uploaded by

sanil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

PROGRAM: B.Sc.

IT
SEMESTER: V
The C# SUBJECT: Advanced Web Programming
Language SUBJECT CODE: USIT503
UNIT: I
TOPICS: Namespaces and Assemblies,
Inheritance
• To study the creation of user –
defined namespaces
LEARNING • To understand the importance of
assemblies
OUTCOMES • To learn the implementation of
inheritance
NAMESPACES

Namespaces can organize all the different types in the class library.

Namespaces don’t take an accessibility keyword and can be nested as


many layers deep as you need.
VIDEO: https://youtu.be/bO_Pigo60TA
namespace MyCompany
{
namespace MyApp
{
public class Product
CREATING {
NAMESPACES // Code goes here.
}
}
}
“using” keyword

using MyCompany.MyApp;

IMPORTING Situation without importing a namespace:


NAMESPACES • MyCompany.MyApp.Product salesProduct =
new MyCompany.MyApp.Product(. . .);

Situation when you import a namespace:

• Product salesProduct = new Product(. . .);


Physical files that contain
compiled code.

ASSEMBLIES Assembly files have the


extension .exe if they are
stand-alone applications.

.dll if they’re reusable


components.
An assembly can contain
multiple namespaces.

ASSEMBLIES Technically, namespaces are a


logical way to group classes.

Assemblies, however, are a


physical package for
distributing code.
The .NET classes are actually contained
in a number of assemblies.

ASSEMBLIES For example, the basic types in the


System namespace come from the
mscorlib.dll assembly.

Often, assemblies and namespaces


have the same names.
INHERITANCE
CODE REUSE.

ALLOWS ONE CLASS TO ACQUIRE


AND EXTEND THE FUNCTIONALITY
OF ANOTHER CLASS.
TYPES OF INHERITANCE
SINGLE INHERITANCE
MULTILEVEL
INHERITANCE
MULTIPLE INHERITANCE
Enumeration
In C#, an enum (or enumeration type) is used to assign constant names
to a group of numeric integer values. It makes constant values more
readable, for example, WeekDays.Monday is more readable then
number 0 when referring to the day in a week.

An enum is defined using the enum keyword, directly inside a


namespace, class, or structure. All the constant names can be declared
inside the curly brackets and separated by a comma.
Enum program
using System;
namespace MyApplication
{ class Program
{ enum Months
{ January, // 0
February, // 1
March=6, // 6
April, // 7
May, // 8
June, // 9
July // 10 }
static void Main(string[] args)
{
int myNum = (int) Months.April;
Console.WriteLine(myNum);
} } }
TAKE HOME TASK

PBL #4
• Write a program in C# to implement Multilevel inheritance with the following scenario:
• Class 1 should take student details and should have its own display function to display student
name and roll no.
• Class 2 should be inherited from Class 1 and should take the student’s marks details and must
have it’s own display function to display the marks taken as an input
• Class 3 should calculate the result and display the same using a display function.
• Finally, last class should have the “Main” method for executing the whole program.
THANK YOU!

You might also like