Friday, June 19, 2009

OOPS - Part 1

Classes
A class is the most powerful data type in C#. Like structures, a class defines the data and behavior of the data type. Programmers can then create objects that are instances of this class. Unlike structures, classes support inheritance, a fundamental part of object-oriented programming. Classes are Template of an Object.
The class keyword is preceded by the access level. In this case
public is used, meaning anyone can create objects from this class. The name of the class follows the class keyword. The remainder of the definition is the class body, where the behavior and data are defined. Fields, properties, methods, and events on a class are collectively referred to as class members.
Objects
Objects are instance of a class and it’s a concrete Entity Objects are programming constructs that have data, behavior, and identity.
Object data is contained in the fields, properties, and events of the object, and object behaviors are defined by the methods and interfaces of the object. Objects have identity — two objects with the same set of data are not necessarily the same object.
Objects in C# are defined through classes and structs — these form the single blueprint from which all objects of that type operate.
Structs Overview
Structs are used for representing the light weight objects
Structs have the following properties:
Structs are value types while classes are reference types.
Unlike classes, structs can be instantiated without using a new operator.
Structs can declare constructors, but they must take parameters.
A struct cannot inherit from another struct or class, and it cannot be the base of a class. All structs inherit directly from System.ValueType, which inherits from System.Object.
A struct can implement interfaces.

No comments:

Post a Comment