Menu
e-lo
  • Home
    • Tech
    • Inspiration and about
  • Database
    • T-SQL
    • SQL Server quick
    • SQL server docs
    • MySql quick sheet
    • Postgre
    • InfluxDB
  • Programming
    • Automating the boring stuff
    • Python 101
    • Python Docs
    • Python Logging
    • Powershell 4 lang ref
    • MS Azure PS
    • MS Azure Command-Line Interface (CLI) doc
  • Azure
    • AZ-104-MS Azure Administrator 101 quick ref
    • AZ-104 Lab
    • MS Windows virtual machines in Azure
    • MS ARM Docs
    • MS ARM Template Docs
    • MS ARM Tutorial
    • MS Deployment scripts (intern/extern)
    • ARM Quickstart
    • MS ARM templates 4h
  • Az Adm
    • AD 101
    • Governance and Compliance 102
    • Administration 103
    • Virtual Networking 104
    • Storage 107 (With table (NoSQL and more))
    • Virtual Machines 108
    • Azure Virtual Machines 101
    • Monitor VM (and market)
  • Linux
    • Top CMD’s
    • Useful CMD Linux
    • ss64 Linux
    • Ubuntu
    • 30 things Ubuntu 18.04
    • Bootable Ubuntu USB
    • LinuxFilesystemTreeOverview
  • Zen
    • Not thinking about anything is Zen
e-lo

NET console application using Visual Studio Code 101

Posted on November 27, 2020November 30, 2020 by espenk

https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio-code

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

Prerequisites
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

Yea…

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.

Terminal

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:

https://www.tutlane.com/tutorial/csharp/csharp-classes-and-objects-with-examples

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;
            work();

        }
        public void work()
        {
            Console.WriteLine("loops");
            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine(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++)
            {
                Console.WriteLine(names[i]);
            }

            ArrayList arr = new ArrayList();
            arr.Add(45);
            arr.Add(55);
            foreach (int aa in arr)
            {
                Console.WriteLine(aa);
            }
            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;
                }

            }
        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()
        {
            try
            {

                using (SqlConnection sqlCon = new SqlConnection(connectionString))
                {
                    string q = "SELECT name, database_id FROM sys.databases";
                    SqlCommand command = new SqlCommand(q, sqlCon);
                    command.Connection.Open();
                    command.ExecuteNonQuery();
                    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)
            {
                Console.WriteLine(e);
            }

        }

Debug a .NET console application using Visual Studio Code

RSS Azure

  • Insights and best practices to run business-critical applications on Azure April 8, 2021

RSS Python

  • PEP 656: Platform Tag for Linux Distributions Using Musl March 17, 2021

Cloud

Ansible (1) ARM (7) azure (23) cmd (1) Django (4) Docker (1) e-lo (2) Flask (2) Github (9) Grafana (2) Information (1) Information Retrieval (12) JAVA (1) kivy (2) Kotlin (4) linux (13) mobile (2) Natural Language Prossesing (NLP) (2) Net.Core (1) Networking and Security (2) OPC (2) PEP8 (1) Philosophy (3) Python (42) Python Networking and Security (2) Reason (2) RMQ (2) Solr (11) Sql (10) VSC (1) Warframe (2) WMVARE (4) Zabbix (7)

Recent Posts

  • TODO Ubuntu Ubuntu 20.04.2 LTS and Bash
  • Disk measurements with typeperf (Pandas py)
  • 2 TODO Azure, Arm and Bash
  • Cryptography with Python – Caesar Cipher
  • 1 TODO Udemy AZ-104 Microsoft Azure Administrator Exam Certification (Scott Duffy)

Archives

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2021 e-lo | Powered by WordPress & Superb Themes