Docsity

Introduction to OOP - C Sharp Programming - Lecture Slides, Slides of C Sharp Programming

Partial preview of the text

Download Introduction to OOP - C Sharp Programming - Lecture Slides and more Slides C Sharp Programming in PDF only on Docsity!

Introduction to Object-

oriented Programming

in C#

Introduction

 Classes and class relationships are defined using UML Class diagrams  These classes must be implemented  Any OOP language can be used  Visual Basic  C#  Java  C++

Creating a Class (Illustration)

Declaring a Class

 Classes are declared inside of a class block  Syntactically this works the same way as a form  Properties and methods appear inside of the class block  More in a moment

Controlling Visibility with

Access Modifiers

 In a UML diagram, an attribute or operation can be visible or hidden  In C#, keywords called access modifiers define which classes and other assemblies can use a component  Their meaning is the same as their meaning discussed so far

Access Modifiers ( public )

public members are globally accessible and available to other assemblies (components)  Globally available within the component too  Note that Intellisense technology will display exposed members  Members of the .NET Framework class library are public for example

Declaring a Method

(Introduction)

 Remember that methods perform an action  In C#, methods are nothing more than procedures  These are the same procedures that you have used before

Declaring a Method (Example)

 Create a method named Area public class CircleV { public double Area(double argRadius) { return Math.PI * radius * radius; } }

Constructor (Example)

 Create a constructor to increment an instance counter

public Circle() { CallCount++; }

Static Members (Introduction)

 By default, members are instance members  One instance exists for each class instance  Think of a TextBox. One instance of the Text property exists for each control instance  static members belong to the type so one copy exists for all class instances  Declare shared members with the static keyword

Static Members (2)

 Shared members cannot operate on instance data  Instance members can operate with shared data

Why?

The Class View Window (Illustration)

The Class Designer

(Illustration)

The Class Designer

(Illustration)