Lecture 9 - Classes and Object in C#
Lecture 9 - Classes and Object in C#
https://sites.google.com/a/quest.edu.pk/dr-irfana-memon/lecture-slides
Course Content
Review of C# Syntax: Overview of Writing Applications using C#, Data types, Operators, and
Expressions
C# Programming Language Constructs, Creating Methods
Invoking Methods, Handling Exceptions, Creating overloaded Methods
Developing the Code for a Graphical Application: Implementing Structs and Enums
Implementing Type-safe Collections: Creating Classes, Organizing Data into
using System;
using System;
public class Person
using System;
}
}
9
Members Of Class
Class is a mechanism to implement the encapsulation, it bind the data and a function
in a single unit. Therefore data and functions are the members of class, which is
known as member data and member function.
There is an example of full class:
class circle
{
12
Defining a Class (Example)
class Boxtester
{
static void Main(string[] args)
{
Box Box1 = new Box(); // Declare Box1 of type Box
Box Box2 = new Box(); // Declare Box2 of type Box
double volume = 0.0; // Store the volume of a box here
// box 1 specification
Box1.height = 5.0;
15
Exercise : creating class with
instance method, constructor
and destructor
17
// Namespace Declaration
using System;
// helper class
class OutputClass
{
string myString;
18
}
// Namespace Declaration
using System; // Program start class
class ExampleClass
// helper class {
// Main begins program execution.
class OutputClass
public static void Main()
{
{
string myString;
// Constructor }
public OutputClass(string inputString) }
{
19
// Namespace Declaration
using System; // Program start class
class ExampleClass
// helper class {
class OutputClass // Main begins program execution.
public static void Main()
{
{
string myString;
// Constructor }
public OutputClass(string inputString) }
{
// Instance Method
public void printString()
{
Console.WriteLine("{0}", myString);
}
20
}
// Namespace Declaration
using System; // Program start class
// helper class class ExampleClass
class OutputClass {
// Main begins program execution.
{
public static void Main()
string myString; {
// Constructor
public OutputClass(string inputString)
{ }
myString = inputString; }
24
Wish You Good Luck