type of class in c#

tahria123 246 views 16 slides Dec 08, 2017
Slide 1
Slide 1 of 16
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16

About This Presentation

class declaration to member function


Slide Content

Class

CLASS Class is a template, declaration or blueprint that is used for classifying object. It encapsulates variable members, functions, structure, properties and many more components   It is a collection of objects.

CLASS Example “Teachers”, “students” and “staff” members are the instances of “Human” class. “Cat" is an instance of the class “Animal".

DECLARE A CLASS A simple class declaration in C# class Human { //Fields, properties, methods }

OBJECTS Suppose you created a class print that contain following method.  class print   {     public void  printname ()      {         Console.WriteLine ("My name is Steven Clark");      }   } To use the members of class, you need to create object of this class. After creating the object of print class, you can use its members using the object name as follow:  print pr = new print();   pr.printname ();

MEMBER OF CLASS Member variables Member functions

MEMBER OF CLASS MEMBER VARIABLES Variables declared within the scope of a class are known as member variables of that class. MEMBER FUNCTIONS Similarly, functions declared within class scope are known as member functions of that class.

TYPES OF CLASS Static Class Abstract Class   Sealed Class Partial Class

STATIC CLASS A Static Class is one which cannot be instantiated. The keyword new cannot be used with static classes as members of such class can be called directly by using the class name itself. Static Class is denoted by the keyword  static .

PROPERTIES OF STATIC CLASS • A Static Class can only have static members. • A Static Class cannot be instantiated.  • A Static Class is sealed, so cannot be inherited. • A Static Class cannot have a constructor (except static constructor).

EXAMPLE

ABSTRACT CLASS An Abstract Class means that, no object of this class can be instantiated, but can make derivation of this. It can serve the purpose of base class only as no object of this class can be created Abstract Class is denoted by the keyword  abstract .

EXAMPLE

SEALED CLASS A sealed class is a class which cannot be inherited. A sealed class cannot be a base class. The modifier abstract cannot be applied to a sealed class. To create a class as sealed class, create the class using the keyword sealed. [Access Modifier] sealed class classname { }

EXAMPLE