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
- 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
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.
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
Otherwise, you can drag the terminal from the base of the vscode
After setting up VScode on your computer, lets create a web app
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
- 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
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)
- This operation would open some files in that project
- The program.cs folder would create a mini app that would display "Hello World" in your browser
- Run the mini application by typing dotnet run in the terminal
- Run the local host link on a browser to test the application
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
- Change directory to the folder created Type cd + name of the folder you want to open
- Next on your terminal, Type and hit enter dotnet new console -n MyProject -o .
- Just like the web app, go to the program.cs folder to view the existing code.
I got a code for a console snake game and added it.
- Type in dotnet build and dotnet run on your terminal to run the codes
- 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
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
Top comments (0)