Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Class & Object

Ram Sapkota
October 27, 2018
110

Class & Object

Ram Sapkota

October 27, 2018
Tweet

Transcript

  1. Classes  Classes are used to model real world entities.

    It is also referred as a custom data type.  Let’s create a class.  Go to project folder in solution explorer and right click on it.  Go to Add New and than New Item.  Than select class from the menu and give class a name and hit add.  Walla! Class is ready!
  2. Constructors in C# classes  It is a special method

    inside of a class which is going to called each time when we create object of that specific class.  By default there is a hidden constructor in C# classes unless you modify it.  A constructor is a method that has same name as a class.  This method will now be accessed by all objects.
  3. Research on Types of Constructors  Default Constructor  Parameterized

    Constructor  Copy Constructor  Static Constructor
  4. Object Methods  First lets create a class student with

    property name, majorSubject and percentage.  Also lets create a constructor to initialize them  Let’s create a method in that class as below to find qualified or not: Note: above 75 % you are qualified.
  5. Getters and Setters in C#  Getters and setters are

    two types of method that we can define inside of our class which will essentially make your class more secure.  It lets you decide what data is valid for specific attribute and what data isn't valid.  They are extremely useful.
  6. How to! First cut off the property of class using

    access modifier private.  Now let’s male getters and setters for that specific attribute.