Pages

Tuesday, April 9, 2013

How to create class and object in C#


Here I explained what's class and what's object and how to create a class and object,
Class: class is collection member functions and member variables.
Syntax: Class ClassName
   Object:An instance of the class is called object
Syntax: ClassName obj=new ClassName();
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace ConsoleApplication1
{
    class sample
    {
        public void hello()
        {
            Console.WriteLine("Hi this is srinivasulu reddy");
        }
    }
    class Program
    {

        static void Main(string[] args)
        {
            sample s = new sample();
            s.hello();
            Console.ReadLine();
        }
    }
}
output: 

Note:Here I am using Console.ReadLine() for displaying output stability.





















No comments:

Post a Comment