What is an object in C#

No.of Views819
Bookmarked0 times
Downloads 
Votes0
By  gurumatrix2004   On  16 Feb 2010 03:02:51
Tag : CSharp , Miscellaneous
What is an object in C#
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

• An object is a software bundle of variables and related methods.
• Objects are related to real life scenario
• Class is the general thing and object is the specialization of general thing
• Objects are instance of classes.
• Declaration of an Object in C#.NET
• ClassName objectName=new ClassName();
  E.g.: Person objPerson= new Person();

An object is characterized by concepts like:

• Attribute
• Behavior
• Identity

 

1. What is an Attribute?


• Attributes define the characteristics of a class.

• The set of values of an attribute of a particular object is called its state.

• In Class Program attribute can be a string or it can be a integer
 

Example of Attribute:

Image Loading

2. What is a Behavior?


• Every object has behavior

• In C#, behaviors of objects are written in methods.

• If a behavior of an object needs to be performed, then the corresponding method is called.

Example of behavior:

Image Loading

3. What is an Identity?


• Each time an object is created the object identity is been defined.

• This identity is usually created using an identifier which is derived from the type of item

Example of Identity:

Image Loading

 Sample Code Lines

using System;
class SalaryCheque
{
public string _EmployeeName;
public int _Amount;
public string EmployeeName(string name)
{
_EmployeeName = name;
return _EmployeeName;
}
public void EmployeeType(int type)
{
if (type == 1)
{
this._Amount = 50000;
}
if (type == 2)
{
this._Amount = 27000;
}
if (type == 3)
{
this._Amount = 5000;
}
}
public void DisplayCheque()
{
Console.WriteLine("This Month Salary for " + _EmployeeName + " is " + _Amount);
}
}


class SalaryChequeDisplay
{
static void Main()
{
string _name;
int _employeeType;
Console.WriteLine("Please Enter Employee Name");
_name = Console.ReadLine();

Console.WriteLine("Enter Employee type 1 for Manager 2 for Assistant Manager 3 for Worker");
_employeeType = Convert.ToInt16(Console.ReadLine());

SalaryCheque objsal = new SalaryCheque();

objsal.EmployeeName(_name);
objsal.EmployeeType(_employeeType);
objsal.DisplayCheque();
}
 

 

Conclusion

In this article, i have explained what is object and basic concept of the object. i hope this is help to you all.

 
Sign Up to vote for this article
 
About Author
 
gurumatrix2004
Occupation-Not Provided
Company-Not Provided
Member Type-Fresh
Location-Not Provided
Joined date-11 Aug 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top