Microsoft.NET

……………………………………………….Expertise in .NET Technologies

Object Oriented Programming in C#

Posted by Ravi Varma Thumati on July 10, 2009

This tutorial describes the use of object-oriented techniques with the C# programming language. Before we start to examine any sample code, it is important to review the ideas that will be discussed in this tutorial. Some of the key concepts are described in the following sections.

Table of Contents

Introduction…………………………………………………………………………………………………………………..

What is an Object?

What is a Class?

Declaring a Class

Creating Class Members

Accessing Object Members

Adding Methods to a Class

Encapsulation

Passing Messages

Constructors in C#………………………………………………………………………

What is a Constructor?

Types of Constructors

Static Constructors

Non-Static or Instance Constructors

Default Constructor

Constructor Overloading

Constructor Chaining

Constructors and Inheritance

Destructors in C#:…………………………………………………………………………

What is Destructor?

Destructor Working:

Garbage Collector:

Access Modifiers in C#………………………………………………………………….…

Public (C# Reference)

Private (C# Reference)

Protected (C# Reference)

Internal (C# Reference)

Protected internal

Methods in C#…………………………………………………………………………………

What is a Method?

Creating a Method

Naming a Method

Returning From a Method on Completion

Calling a Method

Functional Methods in C#

Functional Methods

Creating a Method that Returns a Value

Adding Parameters

Static Methods

C# Method Parameters

Value Parameters

Passing Value Types by Value

Passing Reference Types by Value

Reference Parameters

Passing Value Types by Reference

Passing Reference Types by Reference

Output Parameters

Parameter Arrays

Properties and Indexers in C#…………………………………………………………

Property

Static Properties

Properties & Inheritance

Properties & Polymorphism

Indexer……………………………………………………………………………………………

A simple indexer

Indexers in inheritance

Indexers can be polymorphic

Abstract indexers

Comparison between properties and indexers

Static Behavior in C#………………………………………………………………………

Why Use Static Behaviour?

Static Methods

Creating a Static Method

Calling a Static Method

Static Properties

Creating a Static Private Variable

Exposing a Static Property

Using a Static Property

Static Constructors

The first pillar of object-oriented programming – Encapsulation….

Introduction:

Why Encapsulation?

There is two ways to create a validation process:

Using Accessors and Mutators:

Using Properties:

The second pillar of Object-Oriented Programming – Inheritance…

Introduction:

The Base class:

The Subclass (derived class):

Creating the subclass:

Using the base class constructors:

The sealed classes:

Multiple Inheritances in C#

Abstract Classes……………………………………………………………………………

What is an Abstract Class?

Creating an Abstract Class

Creating an Abstract Property

Creating an Abstract Method

Creating Concrete Members in an Abstract Class

Inheriting from an Abstract Class

Implementing the Abstract Members

Testing the Subclasses

The third pillar of object-oriented programming – Polymorphism:

Introduction:

The virtual methods:

The sealed keyword:

The abstract methods:

Method Overloading in C#………………………………………………………………

Method Overloading

Creating an Overloaded Method

Automatic Type Conversion

Return Type Limitations

C# Constructor Overloading

Creating Overloaded Constructors

Adding the Constructors

Using Overloaded Constructors

Constructor Interaction

C# Basic Operator Overloading………………………………………………………

Binary Operator Overloading

Creating the Addition (+) Operator

Creating the Subtraction (-) Operator

Creating the Multiplication (*) Operator

Compound Assignment Operators

Unary Operator Overloading

Overloading True and False in C#

Adding True and False Operators (Default Behavior)

Overloading True and False

C# Logical Operator Overloading

Overloading the Binary Boolean Logical Operators

Overloading the Unary Boolean Logical Operator

C# Relational Operator Overloading

Overloading the Equality and Inequality Operators

The Equals Method

The GetHashCode Method

Overloading the Comparison Operators

C# Conversion Operator Overloading

Creating an Implicit Conversion Operator

Adding Double Conversion to the Vector Class

Creating an Explicit Conversion Operator

Understanding Interfaces in C#………………………………………………………

Introduction

What Interfaces Are Not

When to Use Interfaces

Creating an Interface

Implementing an Interface

Using Interfaces

Enumeration in C#………………………………………………………………………….

Introduction

Underlying Types:

Delegates and Events……………………………………………………………………..

Delegate

Declaring a delegate

Instantiating a delegate:

Calling a delegate:

Delegates vs. Interfaces

Delegates are useful when:

Interfaces are useful when:

Events in C#

Introduction

Example:

Abstract Class vs. Interface……………………………………………………………

Introduction

Background

What is an Abstract Class?

What is an Interface?

Both Together

Using the Code

Code for Testing

Advertisements

One Response to “Object Oriented Programming in C#”

  1. Zeme said

    best website

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: