Thursday, December 6, 2018
Home > C# > Getting Started With C#

Getting Started With C#

Getting started with C# and to write programs in it, we require a platform where we will be able to write code and then execute it.
Here you can find out about C# compilers.
There are two ways to run a C# program.

  1. Using command line.
  2. Using an IDE.

Writing your First program using Command Line

In order to run a program from command line, we should follow these steps:
Open a text editor and write your first program in it using C# language.

save as

Save it with .cs extension.

.cs Extension

Open command prompt tool.

Command line

Go to the directory where you saved your file.

Command Line directory

Type csc filename.cs and press enter. It will compile your code. And if there are no errors in your code it will make another file with .exe extension. Here .exe (executable file) file name will be same as for your file with .cs extension.
Type filename and hit enter to run your executable file.
Now you should see output for your program on the screen.

Command Line

Writing your First program using IDE

We are using visual studio Community 2017.You can download it from Link. Once you download it from the link given, run the installer and install it to a suitable directory. Then follow these steps.
Open your IDE, i.e., in our case visual studio.

Go to file -> new -> project

getting started with c# - Create Project
A window will open.
Select visual C# from templates and then console application.
Write the name of your program and choose the directory where you want to save your program.

getting started with c# - Create Project

Click ok. And a window will open, and you are ready to write your first program.

getting started with c# - Write your program
Now write your code.

using System;

namespace first_program
     class Program
          static void Main(string[] args)
               Console.WriteLine("This is a test program!!!!");

Once you have written your code save it using Ctrl+S or file -> save.

getting started with c# - Save File

Now click on Debug -> start without Debugging or just press Ctrl+F5.

getting started with c# - Start without Debugging
It will build your program, and If there are no errors in your program, you should see the output on the console screen.

getting started with c# - Example

From here on you are ready to go and can make and run your applications in C#.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.