Learning how to build a .net core application using Visual Studio and C#

Here we go over the steps to building our first application using C# and Visual Studio. In order to complete this you might need to download Visual Studio. You can find the free version on my Useful Downloads page.

    1. Open visual studio (I’m using 2019)

    2. Create a new project > Console App (.Net core)

    3. Be sure to select C# from the language drop down

    4. Hit next

    5. Name it “Hello World” and hit “Create”

    6. Now you should be looking at the code editor for a “Console app”

    7. Here is what mine looks like.

    8. OK! now that we have created our project, we discover that Visual Studio actually does all of the code for a “Hello World” app for you so technically you are done! If you want to see it in action you can just “hit play” and see the results! Look at that! You have successfully learned how to build a .net core application!

    9. Before we pat ourselves on the back let’s go over a couple things.

    10. First off on the left you should see the “solution explorer” this is an area in Visual Studio that keeps track of your solution and project files.
    11. I wont go into detail what these are but will simply say that in general a solution is a collection of programming files that need to go together to make a program run and a project is an individual application that does something.For the most part you don’t really need to worry about anything in the solution explorer at this point except the file that we see named “Program.cs”
  • A .cs file is a file type that is used to write C# code most of the time your code will be in a .cs file.
  1. Let’s rename Program.cs to something a little more distinct. (There is no reason that you NEED to do this however its good to have proper names for things when you start building bigger apps)
  2. Right click “Program.cs” and “Rename” to “HelloWorld.cs”
  • OK now let’s talk briefly about the code.

    1. In the middle of the screen you have the code editor and there is alot of stuff going on I’ll go over each piece quickly.
    2. using System;
      1. One of the great things about .net is that alot of the kinda mundane things that you would do in programming has been packaged into .net allowing you to use pre-packages code methods to do things that might otherwise be challenging. To do this we add a reference to the namespaces that we want to use and this makes those packages of code available to use.
      2. So to make a long story short we are using the “System” namespace.
    3. namespace Hello_World
      1. Here we have created our own namespace and if we needed to use the code here in another app we could do a “using Hello_World” to allow us access to the code we have written here. I won’t go into this now just know that you need a namespace
    4. class HelloWorld
      1. A simple mans explanation of a class is that it is a designation for a collection of variables. If you we’re to have a person class you would know that that code represented a person and the variables contained in the class would likely describe the individual attributes of a person. i.e. a person has an Age , a weight, a height etc. Here is a link to more details about classes.
    5. static void Main(string[] args)
      1. this is a method (or function) for a console app you MUST have a Main method.
    6. Console.WriteLine(“Hello World”);
      1. ahhhh we have finally got to some code we can modify!
        1. Console means that we are using the Console code provided by .net if you delete this line and retype in “Console.” you will get a handy list of all of the methods that are available to you to use with the console.
        2. WriteLine means exactly how it sounds. “Write a line to the Console with the text I am about to provide”
        3. (“Hello World!”) the parenthesis tell us that we are providing arguements to the “WriteLine” method the “Hello World!” is surrounded by “” so that we can let the application know that we have started a string type variable and the second ” lets it know that we have ended it!
        4. add a close parenthesis (you are almost always going to have ” ” and ( ) in pairs )
        5. and finally the ; the semicolon lets the app know that you are at the end of the line.

I hope that someone out there finds this tutorial useful! You have just learned how to build a .net core application but we still have so much more to learn! Stick around and follow my blog to learn more about developing in .net!


Leave a Reply

Your email address will not be published.