Development Environment Installation

Note: The video was recorded using Visual Studio 2017. The following steps are for Visual Studio 2019, but the process is the same. You can find a video with Visual Studio 2019 here

1 - Download and Install Visual Studio 

In this first entry, we'll start with the most basic yet most important step: installing and setting up our development environment. 

A development environment is the application we use to program.

Specifically, to program in .Net we will use Visual Studio, which can be downloaded here in Spanish for free and officially.

 

Once on the link, we download the Community version.

download visual studio 2019

What gets downloaded is the installer launcher. Once it's downloaded, we need to open it. It will then download the actual installer.

 

visual studio installer

Once the installation is finished, the Visual Studio installer will open automatically. For example, if you have both the 2017 and 2019 versions, both will appear in a single installer.

The window you'll see looks like this, and it contains several components you can add to Visual Studio.

These components can be added individually or in packages, which is much more convenient. 

visual studio 2019 installation

For us, only one of the packages is necessary: the one that includes ".Net Core." Click on install.

The download size is fairly large, around 7GB, so it might take a while. When finished, you’ll see that in the same launcher there will be a "Launch" button. Click it (or find it in the start menu) to open Visual Studio 2019.

2 - Creating an Application in Visual Studio

In the next window you’ll have several options

  • Clone code (from a repository)
  • Open a project or solution
  • Open a folder
  • Create a new project

select project visual studio

In our case, the option we want is to create a new project.

Clicking it will open another menu, where you can choose what type of project you want to create.

In this window, you can find several filters

  • Type of recently used project
  • Project language (in our case, we'll use C#)
  • Platform compatible with the project type
    • Because it's not the same to program for Android as it is for iOS, and all of this is possible from Visual Studio
  • Type of project
    • You can create mobile apps, desktop apps, IoT, and many more

We need to select the first option: Console Application (.NET Core)

Click Next, and you’ll be prompted to enter a name for your project, and select the folder where it will be located. I personally recommend creating a folder in C:\ called "proyectos", and placing all your projects there. Also, enter a name for the solution, usually the same as the project.

And that’s it! This will create your first console application.

Why .NET Core?

There are several reasons why I recommend using .NET Core. The main and most important one is because it runs on all platforms: Windows, iOS, and Linux. This very website is programmed in .NET Core and running on a Linux server. I’ll prepare a video to show you the steps to do this.

Another very important point, at least for me, is the IDE or development environment, which is Visual Studio. It has no rival in any other programming language.

3 - First "Hello world" Application

As you can see, by default Visual Studio gives us a "hello world"

static void Main(string[] args)
{
    Console.WriteLine("Hello World!");
}

If you click the "Play" button in Visual Studio, it will run the application and print "hello world"

 

That’s how simple and easy it is to run your first "Hello world".

Before moving on, it's important to note that when you create a new console project, there will always be a class called Program and a Main method as the main entry points. These can be changed, but it's standard practice not to do so.

4 - Program Structure 

To create a class you need to:

Right click on the project > Add new item > Select class

And you’ll get something very similar to the following:

class Vehiculo{
}

Classes have methods and properties as their main elements, but they can also contain events, delegates, or other classes inside them. We'll see more about this later. 

4.1 - Properties

Properties are attributes that hold a value at the class level.

class Vehiculo{
    public decimal VelocidadMaxima { get; set; }
}

As we see in the example, the property is created as follows:

  • Access modifier “Public”
  • Data type “Decimal”
  • Property name “VelocidadMaxima”
  • A “set” to assign a value
  • A “get” to read the value
  •  

4.2 - Methods

Methods are blocks of code whose purpose is to perform actions. 

The most common method in all classes is the constructor, which is written as follows: 

class Vehiculo{
    public decimal VelocidadMaxima { get; set; }

    public Vehiculo(decimal velocidadMaxima){
        VelocidadMaxima = velocidadMaxima;
    }
}

As we see, it has the same name as the class. Constructors are also used to assign values to the class’s properties.
To assign values to properties, you have several options:

  • Assign the value directly inside the constructor
  • Pass the value to the constructor
  • Use another method to assign the value
  • Assign the value directly after the class is instantiated

In our example, we’ll use the option of passing the value to the constructor.

For the example, I’ll create another variable that holds the fuel consumption per kilometer.

This allows us to create another method that returns the total consumption over a certain number of kilometers.

class Vehiculo{
    public decimal VelocidadMaxima { get; set; }
    public decimal ConsumoPorKilometro { get; set; }

    public Vehiculo(decimal velocidadMaxima, decimal consumoPorKilometro){
        VelocidadMaxima = velocidadMaxima;
        ConsumoPorKilometro = consumoPorKilometro;
    }

    public decimal ConsumoTotal(decimal kilometros){
        return ConsumoPorKilometro * kilometros;
    }
}

As you can see, in this case, it’s a bit different, as the method has another data type after the word "public", this is the method's return type. 

The Importance of Variable Names

It's important to highlight this, as it's something that junior programmers often overlook: the names of properties/variables and methods.

It's important that both properties and methods have self-explanatory names. What do I mean by this? If we name a property "VelocidadMaxima" (maximum speed), everyone who reads the code later knows that this property holds the maximum speed. However, if we call it “xmx,” no one will understand what that property is for.

4.3 - Comments

Comments are text blocks added manually to explain what’s happening in the code. If any part of the code is very complex or confusing, you'll need to add comments. However, as just mentioned, ideally each variable, property, and method name should clearly indicate its purpose.

There are 3 ways to add comments:

  • Single-line comments with "//"
  • Block comments: "/* text */"
  • Function documentation: "///" 
    • If you type 3 backslashes above a function, the IDE will automatically create a comment block including:
      • <summary> to explain what the function does
      • <param> for each of the input parameters
      • <returns> to indicate what the function returns
//line comment

/*
    Block comment
*/

/// <summary>
/// Indicates the amount of gasoline consumed
/// </summary>
/// <param name="kilometros">Enter the kilometers driven</param>
/// <returns></returns>

As you can see, if variables and methods have appropriate names, using comments is not necessary as they provide information we already have.

4.4 - Access Modifiers

We'll briefly cover this section, as I'll make another video explaining it in more detail. I’ll just list them and mention their features.

An access modifier, as its name suggests, determines the accessibility of our methods or properties from other members or referencing classes. 

The main ones are: 

  • public, no restrictions
  • internal, can only be accessed from within the same project
  • private, only accessible from the class where it's defined
  • protected, from the class itself and its derived classes

By default, in .NET the access modifier is “internal”

4.5 -Namespace Declaration

What is a namespace?
A namespace is where we organize all the classes and files of our project. In the background, it uses an XML language to describe which classes are in each namespace, allowing them to be used without the “using” directive, which lets you use classes from other namespaces (something used a lot day to day). 

Using namespaces helps us avoid ambiguity with class names, since you can't have two classes with the same name in the same namespace, but you can in the same project if they're in different namespaces. 

This post was translated from Spanish. You can see the original one here.
If there is any problem you can add a comment bellow or contact me in the website's contact form

Uso del bloqueador de anuncios adblock

Hola!

Primero de todo bienvenido a la web de NetMentor donde podrás aprender programación en C# y .NET desde un nivel de principiante hasta más avanzado.


Yo entiendo que utilices un bloqueador de anuncios como AdBlock, Ublock o el propio navegador Brave. Pero te tengo que pedir por favor que desactives el bloqueador para esta web.


Intento personalmente no poner mucha publicidad, la justa para pagar el servidor y por supuesto que no sea intrusiva; Si pese a ello piensas que es intrusiva siempre me puedes escribir por privado o por Twitter a @NetMentorTW.


Si ya lo has desactivado, por favor recarga la página.


Un saludo y muchas gracias por tu colaboración

© copyright 2025 NetMentor | Todos los derechos reservados | RSS Feed

Buy me a coffee Invitame a un café