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

Lecture 03 - programming fundamentals

Uploaded by

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

Lecture 03 - programming fundamentals

Uploaded by

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

Language Fundamentals

Object oriented with visual programming


M. Y. A Rahman
Language concept
OOP’s Overview
• OOP – The core ingredient of the .NET framework.
• The fundamental idea behind OOP
• Combine into a single unit(data & methods).
• Such units are called an object.
• All OOP languages provide mechanisms help to implement the object
oriented models
• Encapsulation
• Inheritance
• Polymorphism
• Reusability
Classes and objects

• A class declaration consists of a class header and body.


• The class header includes attributes, modifier and the class keyword.
• The class body encapsulates the members of the class, that are the data
members and members functions.
• Each object contains data methods to manipulate and access that data.
• Definition of a class:
AttributedAccessbilityModifier Class_Identifier Class_Name :Baselist
{
Body
}
• Attributes provides additional context to a class like adjectives
• Eg: Serializable attributes

• Accessibility is the visibility of the class


• The default accessibility of a class is internal
• Private is the default accessibility of class members.
Keyword Description

Public Public class is visible in the current and referencing assembly. (Access is not
restricted)
Private Visible inside current class

Protected Visible inside current and derived class

Internal Visible inside containing assembly

Internal protected Visible inside containing assembly and descending of the current class
• Modifiers define the declaration of a class
• The Base list is the inherited class
• By default, classes inherit from the system.object type.
• A class can inherit and implement multiple interfaces but doesn't support
multiple inheritances.
Creating class & Instance
• using System;
• using System.Collections.Generic;
• using System.Linq;
• using System.Text;
• using System.Threading.Tasks;

• namespace consoleprogram6
• {
• internal class Program
• {
• //Creating a class
• class Customer
• {
• public int cusid = 100;
• public String name = "Gayan";

• }
• static void Main(string[] args)
• {
• //creating a class object
• Customer obj = new Customer();
• Console.WriteLine(obj.name);
• Console.WriteLine(obj.cusid);
• Console.ReadKey();
• }
• }
• }
GET and SET

• Getters and setters are used to protect your data, particularly when creating
classes.
• The get method returns the value of the variable name . The set method
assigns a value to the name variable
• For each instance variable, a getter method returns its value while a setter
method sets or updates its value. Given this, getters and setters are also
known as accessors and mutators, respectively.
GET and SET cont.,

• The code block for the get accessors is executed when the property is read;
the code block for the set accessor is executed when the property is
assigned a new value.
• A property without a set accessor is considered read-only. A property
without a get accessor is considered write only. A property that has both
accessors is read-write
• Property is called as a smart variable that make private variables as
properties and assign values.
Program 07: write a console program with get and set(name and DOB)
• using System;
• using System.Collections.Generic;
• using System.Linq;
• using System.Text;
• using System.Threading.Tasks;

• namespace consoleprogram7
• {
• class student
• {
• String name;
• String dob;
• public String Name
• {
• get { return name; }
• set { name = value; }
• }
• public String Dob
• {
• get { return dob; }
• set { dob = value; }
• }
• }
• internal class Program
• {
• static void Main(string[] args)
• {
• student student = new student();
• student.Name = "Kasun";
• student.Dob = "1999-11-10";
• Console.WriteLine("Name is: "+student.Name + "DOB is: "+student.Dob);
• Console.ReadKey();
• }
• }
• }

You might also like