Professional Documents
Culture Documents
Objects in C#:
An entity that has state and behavior is known as an object e.g. pen, table, car etc. It can be
physical or logical .
An object has three characteristics:
identity: Object identity is typically implemented via a unique ID. The value of the ID
is not visible to the external user. But,it is used internally by the JVM to identify each
object uniquely.
For Example: Pen is an object. Its name is Parker, color is black etc. known as its state. It is
used to write, so writing is its behavior.
Object is an instance of a class. Class is a template or blueprint from which objects are
created. So object is the instance(result) of a class. For example, you have a class called
Vehicle and car is the object of that class.
Classes in C#:
1 namespace HelloWorld
2
3
{
4
class firstProgram
5
{
6
public static void Main(string[] args)
7
{
8
Console.WriteLine("Hello World !!");
9
1
}
0
1
}
1
}
1
2
The public keyword is an access modifier that tells the C# compiler that any code
can call this method.
The static modifier tells the compiler that the Main method is a global method and
the class doesnt need to instantiated for the method to be called.
The given code shows the Main method as returning void and not receiving
anyarguments. However, you can define Main method to return a value and take
array of arguments
data member
properties
constructor
methods
Notes:
Class name should start with uppercase letter and be a noun e.g. String, Color,
Button, System, Thread etc.
A class can have a data member which is an object reference of the same class Like
the manager of the employee is also a employee.
Example:
1 class Employee
2{
3 int empNo;
4 string empName;
5 Employee Manager;
6
7
8}