# Introduction to C# and .NET

![](imgs/1%20Introduction%20to%20C%23%20and%20NET_0.png)

---

# Overview

Installing Visual Studio

A Brief History of .NET and C#

Creating Your First Application

Statements

Errors in Visual Studio 2022

Comments

# Installing Visual Studio

* Note: Visual Studio and Visual Studio Code are NOT the same thing
  * Visual Studio is a full-blown IDE (integrated development environment)
  * Visual Studio Code is more akin to text editors like Sublime Text, Atom etc.
  * While both can  be used in certain situations, the C# and ASP.NET portions of this training assume that you are using Visual Studio
* You can download the free version (Visual Studio Community) from  [https://visualstudio.microsoft.com/vs/community/](https://visualstudio.microsoft.com/vs/community/)
* This downloads the setup executable for VS, which will be used to download all the modules needed (see the next slide)

# Installing Visual Studio (cont.)

* After launching the setup executable, you will be prompted to select the components to be installed along with VS. For our purposes you will need "ASP.NET and web development" portion, found in the "Workloads" tab
* Click "Install" found in the lower right corner to begin installing VS and the required components
* Note: The installation can be quite large (8 GB or more) depending on which components are already installed on your system, so we recommend using a personal hotspot if possible
  * Multiple people downloading large amounts of data using the same public WIFI network will bog down the download speed for everyone
* After installing VS, you can skip the account creation portion

![](imgs/1%20Introduction%20to%20C%23%20and%20NET_1.png)

# .NET

* .NET is Microsoft's software framework that turns your code (C#, F# or VB) into machine language
* Two types of .NET Frameworks:
  * .NET Framework
    * 2001
    * Windows only
    * Comes pre-installed with every Windows OS
  * .NET Core
    * 2016
    * "Successor to .NET Framework"
    * Open source!  [https://github.com/dotnet/](https://github.com/dotnet/)  _core_
    * Cross-platform (Linux, Mac, Windows)
    * We will be using .NET Core during this course as the old .NET Framework is pretty much legacy

* Base Class Library (BCL)
  * A set of libraries that every .NET implementation uses
  * The libraries consist of common activities, like classes and value types, that you will use to create your programs
  * No need to reinvent the wheel with every new project

using System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

# C#

C# was developed for .NET Framework in 2000

Microsoft wanted a Windows exclusive competitor for Java

Easy to understand, general purpose, object oriented

![](imgs/1%20Introduction%20to%20C%23%20and%20NET_2.png)

Source:  [http://pypl.github.io/PYPL.html](http://pypl.github.io/PYPL.html)

# Creating a Console Application

Open Visual Studio 2022.

Select "Create a new project"

Type "console" to the search bar and select the following template:

![](imgs/1%20Introduction%20to%20C%23%20and%20NET_3.png)

# Running a Console Application

To run your program, select "Debug" -> "Start Debugging"  __or __ press F5  __or __ press the small play sign preceding your project name at the top middle

The template project should now run and print "Hello World!" to the console. Try changing the code so that it prints something else!

# C# Syntax - Statements

```c#
using System;

namespace MyAwesomeProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}
```

Rows = statements

Curly brackets ' _{' _ and ' _}' _ mark the start and the end of different  _bodies _ of statements

Semicolon at the end of some statements

When to use semicolon? Don't worry: Visual Studio will tell you

# C# Syntax - Errors in Visual Studio 2022

Why is this throwing an error?

Missing one closing curly bracket

![](imgs/1%20Introduction%20to%20C%23%20and%20NET_4.png)

Hovering on the red underline will show a hint for the error:

![](imgs/1%20Introduction%20to%20C%23%20and%20NET_5.png)

All errors can be displayed by pressing the red cross in the bottom:

![](imgs/1%20Introduction%20to%20C%23%20and%20NET_6.png)

# C# Syntax - Comments

There are two basic ways to comment in C#:

// This is a comment

/* This is a

multi

line

comment */

Any text inside a comment will not be executed

Use comments to explain your code or comment out actual code for testing and debugging

## try online

https://www.programiz.com/csharp-programming/online-compiler/

# Assignments

[Assignments about this topic can be found here](https://gitea.buutti.com/education/academy-assignments/src/branch/master/C%23%20Basics/1.%20C%23%20Basics%20Assignments)

