NET console application using Visual Studio Code 101

Extensions I use, C# is the one to install now.

Visual Studio Code with the C# extension installed. For information about how to install extensions on Visual Studio Code, see VS Code Extension Marketplace.
The .NET 5.0 SDK or later


The folder name becomes the project name and the namespace name by default. You’ll add code later in the tutorial that assumes the project namespace is HelloWorld.


dotnet new console

Run the app

Run the following command in the Terminal:

Enhance the app

Open Program.cs by clicking on it.

The first time you open a C# file in Visual Studio Code, OmniSharp loads in the editor.
Select Yes when Visual Studio Code prompts you to add the missing assets to build and debug your app.

After you have done some changes, In Visual Studio Code, you have to explicitly save changes. Unlike Visual Studio, file changes are not automatically saved when you build and run an app.

Great, we done some changes, not lets add a separate class in a different folder.

Classes and Objects:

So here we created a new class and made two instances of it, the field W_id and Name we can get, the property Location we can set and get.

Some more refresh on dotnet, arry, arraylist (using systems.collections), hashtable (dictionary) and the cool goto with for and foreach st.

using System;
using System.Collections;

namespace HelloWorld
    // class name
    class Worker
        // fields
        public int W_id;
        public string Name;
        // constructor
        public Worker(string name)
            Random rnd = new Random();
            W_id = rnd.Next(1, 5555);
            Name = name;

        public void work()
            for (int i = 0; i < 3; i++)


            for (int i = 0, j = 1; i < 3; i++, j++)
                Console.WriteLine(i + " " + j);
            string[] names = new string[3];
            names[0] = "Dimmu B";
            names[1] = "Gorgoroth";
            names[2] = "Trelldom";

            for (int i = 0; i < names.Length; i++)

            ArrayList arr = new ArrayList();
            foreach (int aa in arr)
            Hashtable ht = new Hashtable();
            ht.Add("Jones", "Tom");
            ht.Add("Oneil", "Jane");
            ht.Add("Boris", "Petro");
            foreach (DictionaryEntry item in ht)
                Console.WriteLine(item.Key + " " + item.Value);
                if (item.Value.ToString() == "Petro")
                    goto removeit;

            Console.WriteLine("Can safefully remove it");

        // method
        public void getDetails()
            Console.WriteLine(Name + " " + W_id + " " + Location);
        // properties
        public string Location { get; set; }


Add a package

Go to terminal and type

dotnet add package System.Data.SqlClient

using System.Data.SqlClient;

public void listDatabases()

                using (SqlConnection sqlCon = new SqlConnection(connectionString))
                    string q = "SELECT name, database_id FROM sys.databases";
                    SqlCommand command = new SqlCommand(q, sqlCon);
                    SqlDataReader sqlReader = command.ExecuteReader();
                    while(sqlReader.Read()) {
                        string name = sqlReader["name"].ToString();
                        string id = sqlReader["database_id"].ToString();
                        Console.WriteLine(name + " " + id);

            catch (SqlException e)


Debug a .NET console application using Visual Studio Code

Comments Off on NET console application using Visual Studio Code 101