DEV Community

Cover image for Visual Studio Code: Creating A Console App And A Web App Using C#
John Essien
John Essien

Posted on

Visual Studio Code: Creating A Console App And A Web App Using C#

Hi guys, lets build something using c#!! C# is a versatile programming language that allows developers to build different types of applications. The language is a smart way to structure your code for scalability and reuse! Two of the most common types of applications are 🖥️ Console Applications and 🌐 Web Applications.

In this lesson, we will explore these two application types and how to create them using .NET. Roll up your sleeves and without further ado, lets go to the cloud.


  • To begin with, we'll need to download VSCode (Visual Studio Code). Here is a link to download Visual studio code

Vs code downloads

Download Finished

  • In the Visual Studio Code, install the C# Devkit extension from the Extensions Marketplace. You can do this by searching for C# Devkit and clicking on install

Devkit install

Notice that my Dev Kit Extension is telling me to uninstall. I already installed the kit) This would not be the case for a new user.

  • Download and install the latest version of .NET SDK. The .NET Software Development Kit (SDK) includes everything you need to build and run C# applications. To do this, click on view in the vscode, click on command palate and then input .net install new .net sdk.

net sdk workings

net sdk

Or you can download the software development kit here Dotnet SDK

Most of the time, we will be working with terminals on vscode
To get terminal, click on view and then click on terminal

Select terminal

Otherwise, you can drag the terminal from the base of the vscode
drag from base

After setting up VScode on your computer, lets create a web app

  • First, click on file, open folder,
    Open folder

  • Select new folder and give a name
    Name Folder

  • Notice the folder on the top left of the VS code app after creation
    VScode folder

Alternatively, open your terminal
Type mkdir (make directory; a Linux command for creating a file or folder) + name of the folder you want to create

Type Mkdir

  • CD into the directory of the folder A directory is like a wardrobe that holds different compartment. To use the compartment, we need to open the door of the wardrobe.

Since we have created a directory, we need to go inside the directory
Type cd + name of the folder you want to open
CD into the folder

Creating the web app

Web Application: Built for handling HTTP requests, delivering web content, and building RESTful APIs or full-fledged websites.

Type dotnet new web -n MyProject -o .

where:
dotnet is the building tool
Web is the mode of application used
-n is the syntax for name of the project
MyProject is the actual name of the project
-o . is output to current directory (remember we changed directory)

new project

  • This operation would open some files in that project

New files

  • The program.cs folder would create a mini app that would display "Hello World" in your browser

Program CS

  • Run the mini application by typing dotnet run in the terminal

dotnet run

  • Run the local host link on a browser to test the application run local host

Creating the console app

Console Application: Focused on terminal-based interaction, It does not have a graphical user interface (GUI) and is primarily used for executing background tasks, non-interactive tasks, automation, and simple programs. Console applications are command-line programs that interact via text.

  • Create a folder open your terminal and type mkdir (make directory; a Linux command for creating a file or folder) + name of the folder you want to create

Mkdir folder

  • Change directory to the folder created Type cd + name of the folder you want to open

CD into the folder

  • Next on your terminal, Type and hit enter dotnet new console -n MyProject -o .

dotnet new console

  • Just like the web app, go to the program.cs folder to view the existing code. Program cs

I got a code for a console snake game and added it.

Snake game code

  • Type in dotnet build and dotnet run on your terminal to run the codes

dotnet run on the terminal

  • You should see your game running on the terminal. This is because the console application is a terminal-based interaction, It does not have a graphical user interface Snake game

Whenever the codes are modified, there is a need to run dotnet build. The difference between the C# console build and app build lies in the line of code "dotnet new console -n MyProject -o ." While the console uses dotnet new console -n MyProject -o ., the web app uses dotnet new web -n MyProject -o .


Phew!!! That was some cloud workout right?? Stay with me and lets keep building that cloud muscle and I'll catch you in the next article!!!

COMMENT, LIKE, ASK QUESTIONS AND SHARE

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed
  • 2:34 --only-changed
  • 4:27 --repeat-each
  • 5:15 --forbid-only
  • 5:51 --ui --headed --workers 1

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

Watch Full Video 📹️

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay