Thursday, December 30, 2010

Creating a Csharp Console Application

Follow me
Open Notepad
Write the following code in Notepad Or you can use Visual Studio

 using System;

namespace Blog1
{
    class FootballPlayer
    {
        string FootballPlayerName;
        int Rank;

        public void PrintPlayerDetails()
        {
            Console.WriteLine("The Details of the Player are :");
            Console.WriteLine(" Name:");
            Console.WriteLine(FootballPlayerName);
            Console.WriteLine("Rank");
            Console.WriteLine(Rank);
        }
        public void GetPlayerDetails()
        {
            Console.WriteLine(" Enter The Details of Player");
            Console.WriteLine(" Enter Player Name");
            FootballPlayerName = Console.ReadLine();
            Console.WriteLine(" Rank");
            Rank = Convert.ToInt32(Console.ReadLine());
        }
    }
    class Football
    {
        public static void Main(string[] args)
        {
            FootballPlayer P1 = new FootballPlayer();
            P1.GetPlayerDetails();
            P1.PrintPlayerDetails();
            Console.ReadLine();
        }
    }
}

if your using visual Studio you can compile (run) the program by hitting f5 or click the debug button above the visual studio.

if your using notepad save the file as Player.cs , you can give any name you want but should save with c#(c sharp) file extension (.cs)
now open Visual studio command prompt.move to the location where you have saved the program .
Example cd  C:/
C:\>dir
compile the program file by using the following command
csc Player.cs
and  to Execute the program write Player.exe

No comments:

Post a Comment