1. C# (OOP Concepts part 1)

Introducing Classes and Objects
 A class defines constituent members which enable these class instances to have state and behavior.

e.g Vehicle class defined as:

public class Vehicle
{
public string Name;
public string vehicleNo;

public void ShowVehicleInformation()
      {
            Console.Write(this.Name);
            Console.Write(this.vehicleNo);
}
}

Here Vehicle is some thing which has some chracteristics and behaviors.

An object is a building block of an OOP application. This building block encapsulates part of the
application, which may be a process, a chunk of data, or a more abstract entity. Objects in C# are created from types, just like the variables you have seen already. The type of an object is known by a special name in OOP, its class

e.g a variable is declared as               

int myNumber = 10;

Similarly an object is declared as

                                                Vehicle car = new Vehicle();

Here car is an object of Vehicle class. Vehicle can also be called a user defined data type.

Properties and Fields
Properties and fields provide access to the data contained in an object. This object data is what differentiates separate objects, because it is possible for different objects of the same class to have different values stored in properties and fields.

Both fields and properties are typed, so you can store information in them as string values, as int values, and so on.

e.g  car object of Vehicle class has properties:

public string Name;
public string vehicleNo;

Methods
Methods are used to provide access to the object’s functionality.

e.g

public void ShowVehicleInformation()
{
Console.Write(this.Name);
Console.Write(this.vehicleNo);
}
Access Modifiers
All types and type members have an accessibility level, which controls whether they can be used from other code in your assembly or other assemblies. You can use the following access modifiers to specify the accessibility of a type or member when you declare it:
public
The type or member can be accessed by any other code in the same assembly or another assembly that references it.

private
The type or member can be accessed only by code in the same class or struct.

protected
The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.

internal
The type or member can be accessed by any code in the same assembly, but not from another assembly.

Default access
          A default access level is used if no access modifier is specified in a member declaration. The following list defines the default access modifier for certain C# types:
 
enum: The default and only access modifier supported is public.
 
class: The default access for a class is private. It may be explicitly defined using any of the access modifiers.
 
interface: The default and only access modifier supported is public.
 
struct: The default access is private with public and internal supported as well.
 
The default access may suffice for a given situation, but you should specify the access modifier you want to use to ensure proper application behavior.
 
Note: Interface and enumeration members are always public and no access modifiers are allowed.
Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

2 comments: