Wednesday, 10 July 2013

How to Execute C# Program using command prompt

 

 

Open Notepad

Write a sample program

 

image

 

Write bellow code in notepad and save as Test.cs

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter N number");
            int n = Convert.ToInt32(Console.ReadLine());
            int i = 0, sum=0;
            for (i = 0; i <= n; i++)
            {
                sum = sum + i;
            }
            Console.WriteLine(sum);
            Console.ReadLine();

        }
    }
}

save this file in C Drive.

Next open Visula Studio Command prompt.

set the directory in Visual studio Command Prompt

 

image

 

now enter

C:\>CSC Test.cs

image

Enter

image

Enter N

3

Then the result

0+1+2+3= 6

image

No comments:

Post a Comment