Object-oriented concepts form the base of all modern programming languages. Understanding the basic concepts of object-orientation helps a developer to use various modern day programming languages, more effectively. C# (C-Sharp) is an object-oriented programming language developed by Microsoft that intends to be a simple, modern, and general-purpose programming language for application development.
The course is applicable to students who want to enter the world of object-oriented programming, using the C# language. This course provides a strong foundation in object-oriented programming approaches and the fundamentals of C# programming language.
Object orientation is a software development methodology that is based on modeling a real-world system.
An object oriented program consists of classes and objects.
Let us understand the terms—class and objects
An object means a ‘material thing’ that is capable of being presented to the senses.
An object has the following characteristics:
Basic Data Types and their mapping to CTS (Common Type System)
There are two kinds of data types in C#.
C# type .Net type Size in Description
bytes
bool Boolean 1 Contains either true or false
char Char 2 Contains any single Unicode
character enclosed in single
quotation mark such as 'c'
Integral types
byte Byte 1 May contain integers from 0-255
sbyte SByte 1 Signed byte from -128 to 127
short Int16 2 Ranges from -32,768 to 32,767
ushort UInt16 2 Unsigned, ranges from 0 to 65,535
int Int32 4 Ranges from -2,147,483,648 to
(default) 2,147,483,647
uint UInt32 4 Unsigned, ranges from 0 to
4,294,967,295
long Int64 8 Ranges from
-9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
ulong UInt64 8 Unsigned, ranges from 0 to
18,446,744,073,709,551,615
Floating point types
float Single 4 Ranges from ±1.5 × 10-45
to ±3.4 × 1038 with 7 digits
precision. Requires the
suffix 'f' or 'F'
double Double 8 Ranges from ±5.0 × 10-324 to
(default) ±1.7 × 10308 with 15-16 digits
precision
decimal Decimal 12 Ranges from 1.0 × 10-28 to
7.9 × 1028 with 28-29 digits
precision. Requires the
suffix 'm' or 'M'
Examples :
The SalesTaxCalculator class inherits the TaxCalculator and overrides its CalculateTax() method. It applies 30% tax on the price of an item (a bit harsh!) and returns the new price of the item. The SalesTaxCalculator class also defines a constructor that takes itemPrice as its parameter. If we don't provide the implementation of the CalculateTax() method in SalesTaxCalculatorclass SalesTaxCalculator : TaxCalculator { public SalesTaxCalculator(double itemPrice) { this.itemPrice = itemPrice; } /* public override double CalculateTax() { tax = 0.3 * itemPrice; return itemPrice + tax; }*/ }
class SalesTaxCalculator : TaxCalculator { public SalesTaxCalculator(double itemPrice) { this.itemPrice = itemPrice; } public override double CalculateTax() { tax = 0.3 * itemPrice; return itemPrice + tax; } }
abstract class TaxCalculator { protected double itemPrice; protected double tax; public abstract double CalculateTax(); public double Tax { get { return tax; } } public double ItemPrice { get { return itemPrice; } } }