How to Create a Program in C Sharp
How to Create a Program in C Sharp
C# is a great programming language, and all the tools you need to get started are free and easy to use. While C# is usually associated with Microsoft and closed source, you can download a free version of Visual Studio Community and start programming. This wikiHow teaches you how to create a program in C# using Visual Studio.
Steps

Setting Up Visual Studio

Go to https://visualstudio.microsoft.com/free-developer-offers/ in a web browser. This is the website for Visual Studio Express. You can download your free copy of Visual C# Community Edition.

Hover over "Download Visual Studio" and click Download Community 2019. It's the purple button on the left side of the page. Placing the mouse cursor over this displays a drop-down menu with three versions of Visual Studio. Visual Studio Community 2019 is the free version. If the file doesn't download automatically, click the blue text that says Click here to retry at the top to download it again.

Run the downloaded executable. The downloaded executable is called "vs_community__[version number].exe". By default you can find downloaded files in your Download folder or in your web browser.

Click Yes. This gives VS_Community permission to make changes to your Windows system.

Click Continue. It's in the lower-right corner. This begins the process of installing Visual Studio Express.

Click the checkbox Windows regchecked next to .Net desktop development. It has a icon that resembles a computer screen with a purple square that says ".Net". This contains the components for C#. You can also check "Universal Windows Platform development" for additional components related Windows development. Look at all the other workloads and check any additional workloads you want to add. There are workloads related to other languages, like Python and C++, game development, mobile development and more.

Click Install. This installs Visual Studio with the workloads you selected. It may take a while for Visual Studio to download.

Open Visual Studio. Visual Studio has an icon that resembles a purple ribbon. Click the icon in Windows Start menu to open Visual Studio.

Sign in to your Microsoft account. If you don't have a Microsoft account, click Create One and fill out the form to create a new Microsoft account. You can also click Not now, maybe later to skip this step for now. Use the following steps to sign in to your Microsoft account: Click Sign In Enter the email address associated with your Microsoft account. Click Next. Enter the password associated with your Microsoft account. Click Sign In.

Select "Visual C#" as the Development Settings. Use the drop-down menu next to "Development Settings" to select "Visual C#".

Select a color theme. Click the radio option next to the color scheme you want to use in Visual Studio. You can use any color theme you want.

Click Start Visual Studio. This will start Visual Studio.

Creating Your First Program

Open Visual C#. Visual Studio has an icon that resembles a purple ribbon. Click the icon in Windows Start menu to open Visual Studio.

Click Create a new project. It's the last option on the title page.

Select Console App (.NET Core) for C# and click Next. It's the first option at the top of the page. It has a green "C#" icon in the upper-right corner.

Type a name for your project and click Create. Enter whatever name you want to name your project under "Project Name". You can name it "Hello World", leave the default name or pick a different name. Click Create to start your project. You should see some placeholder code that looks like this: using System; namespace Adding { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } }

Remove the line "Console.WriteLine("Hello World!");". It's right under the line that reads "static void Main(string[] args)".

Write int Number1, Number2; in it's place. This goes right after the curly bracket below " static void Main(string[] args)". This line of code declares two new integers (which are numbers) and gives them the label "Number1" and "Number2".

Write Console.WriteLine("Please enter the first number and press Enter:"); in the next line. This goes in the next line after the line that declares two new integers. This line of code instructs the user to enter the first number and press enter.

Write Number1 = Convert.ToInt32(Console.ReadLine()); in the next line. This goes after the line that instructs the user to enter a number. This line of code takes the number the user enters and stores it as a 32-bit floating signed integer and assigns the value to the label "Number1".

Write Console.WriteLine("Please enter the second number and press Enter:"); in the next line. This goes in the next line after the line that converts the first number to an integer. This line of code instructs the user to enter the second number and press Enter.

Write Number2 = Convert.ToInt32(Console.ReadLine()); in the next line. This goes after the line that instructs the user to enter a number. This line of code takes the number the user enters and stores it as a 32-bit floating signed integer and assigns the value to "Number2".

Write int Result; in the next line. This goes after the line that converts the second number to an integer. This line of code declares a new integer with the label "Result".

Write Console.WriteLine("The sum of the two numbers is " + Result.ToString()); in the next line. This goes after the line that declares the Result integer. This line of code adds Number1 and Number2 and stores the sum under the integer label "Result". It then displays that number as a string (text) and displays the result along with a line explaining to the user that this is the sum of the numbers they entered.

Write Console.WriteLine("Press Enter to end program"); in the next line. This goes after the line of code that displays the sum of the two numbers the user entered. This line of code informs the user to press the Enter key to return to the console.

Write Console.ReadLine();. This goes after the line of code that instructs the user to press the Enter key. This returns the user to the command console.

Proof read your code. Go over each line and make sure the spelling and syntax is correct for each line. If it is not, you will get an error message. Also make sure that all open curly brackets "{" have a corresponding closing bracket "}". Your entire page of code should look something like this: using System; namespace Adding { class Program { static void Main(string[] args) { int Number1, Number2; Console.WriteLine("Please enter the first number and press Enter:"); Number1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Please enter the second number and press Enter:"); Number2 = Convert.ToInt32(Console.ReadLine()); int Result; Result = Number1 + Number2; Console.WriteLine("The sum of the two numbers is " + Result.ToString()); Console.WriteLine("Press Enter to end program."); Console.ReadLine(); } } }

Click the Run ► button on the toolbar. It's the green play button at the top of Visual Studio. If everything was entered correctly, this will build the program and run it. The command console will appear. It will tell you to enter a number and press Enter. Then it will tell you to enter another number and press Enter. It will then displays the sum of both those numbers. Congratulations, you just made your first program in C#

What's your reaction?

Comments

https://shivann.com/assets/images/user-avatar-s.jpg

0 comment

Write the first comment for this!