- Back to Home »
- C#.NET »
- C#.NET Object
Posted by :
Sudhir Chekuri
Tuesday, 5 January 2016
- Object is an instance of class.
- Object will have memory.
- Object is used to call methods of a class.
- Object is a reference type.
- To create this object "new" keyword is used.
classname objectname= new constructor();
Example
maths m=new maths();
Example program using object for a class
Program
using System;
namespace Class_Example
{
class Program
{
static void Main(string[] args)
{
maths m = new maths();
m.add();
Console.ReadKey();
}
}
class maths
{
public void add()
{
int a = 10;
int b = 20;
Console.WriteLine("Sum is: " + (a + b));
}
}
}
sum is : 30