Saturday, August 21, 2010

A program consists of two files(class file, csc file)

//csc Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
           Hello Name = new Hello();  //instance Hello class object
           Console.WriteLine("Enter ID 1 or 2");
           Int16 ID = Convert.ToInt16(Console.ReadLine()); //Read the input
           String MyName = Name.FullName(ID); //calling Hello methos
           Console.Write(MyName.ToString()); //Display output
           Console.ReadKey(); //Hold the console application window
          }
      }
}

//Class Hello.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
      class Hello
      {
         public String FullName(Int16 ID)
          {
            if (ID == 1)
               return "Emmaneale";
            else
               return "Mendu";
           }
       }
}

No comments:

Post a Comment