diff --git a/1-introduction-to-csharp-and-dotnet-slides.html b/1-introduction-to-csharp-and-dotnet-slides.html index 3cd5f48..02f9781 100644 --- a/1-introduction-to-csharp-and-dotnet-slides.html +++ b/1-introduction-to-csharp-and-dotnet-slides.html @@ -1,4 +1,4 @@ -
+/* @theme 7sg9195iakay8l0pmu76sdhs4mftnap2jqg3b4z28ojc */div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]{columns:initial!important;display:block!important;padding:0!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]:after,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]:before,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content]:after,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content]:before{display:none!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]{all:initial;display:flex;flex-direction:row;height:100%;overflow:hidden;width:100%}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container][data-marpit-advanced-background-direction=vertical]{flex-direction:column}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background][data-marpit-advanced-background-split]>div[data-marpit-advanced-background-container]{width:var(--marpit-advanced-background-split,50%)}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background][data-marpit-advanced-background-split=right]>div[data-marpit-advanced-background-container]{margin-left:calc(100% - var(--marpit-advanced-background-split, 50%))}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]>figure{all:initial;background-position:center;background-repeat:no-repeat;background-size:cover;flex:auto;margin:0}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]>figure>figcaption{position:absolute;border:0;clip:rect(0,0,0,0);height:1px;margin:-1px;overflow:hidden;padding:0;white-space:nowrap;width:1px}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content],div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=pseudo]{background:transparent!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=pseudo],div#\:\$p>svg[data-marpit-svg]>foreignObject[data-marpit-advanced-background=pseudo]{pointer-events:none!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background-split]{width:100%;height:100%}

Introduction to C# and .NET

-

-
-

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

+
+

Overview

    -
  • Note: Visual Studio and Visual Studio Code are NOT the same thing +
  • C#
  • +
  • .NET
  • +
  • Common Language Infrastructure (CLI)
  • +
  • Base Class Library (BCL)
  • +
+
+
+

C#

+
+
    -
  • 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
  • +
  • The C# (pronounced c sharp) programming language was introduced by Microsoft in 2000, alongside the .NET framework
  • +
  • Unlike C and C++, C# runs on a virtual machine like Java
  • +
  • Easy to understand, general purpose, high-level, object oriented
  • +
  • Resembles Java, which was very popular in the 90s
  • +
  • Newest version is 13.0 from 2024
- -
  • You can download the free version (Visual Studio Community) from 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)
  • +
    + +
    +
    +
    +

    C# Syntax example

    +
    +
    +
    using System;
    +
    +namespace MyAwesomeProgram
    +{
    +    class Program
    +    {
    +        static void Main(string[] args)
    +        {
    +            Console.WriteLine("Hello World!");
    +        }
    +    }
    +}
    +
    +
    +
    +
      +
    • Everything is inside a class
    • +
    • Rows = statements
    • +
    • Curly braces { 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
    • +
    +
    +
    + -

    Installing Visual Studio (cont.)

    +
    +
    +

    .NET

      -
    • 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 +
    • .NET (pronounced dot net) is Microsoft's software framework for building and running web services
    • -
    • After installing VS, you can skip the account creation portion
    • +
    • Fully supports C#, F# and Visual Basic
    • +
    • Implements Common Language Infrastructure, so it can compile managed code (languages above) into machine code
    • +
    • Provides automatic memory management via a garbage collector (GC)
    • +
    • Type-safe and memory-safe thanks to GC and strict compilers
    -

    -

    .NET

    -
      -
    • -

      .NET is Microsoft's software framework that turns your code (C#, F# or VB) into machine language

      -
    • -
    • -

      Two types of .NET Frameworks:

      +
    +
    +

    .NET vs .NET Framework

      -
    • .NET Framework +
    • .NET Framework
        -
      • 2001
      • -
      • Windows only
      • -
      • Comes pre-installed with every Windows OS
      • +
      • Launched in 2001
      • +
      • Closed-source
      • +
      • Windows-only
      • +
      • Current version 4.8.1 launched in 2022
    • -
    • .NET Core +
    • .NET (originally .NET core)
        -
      • 2016
      • -
      • "Successor to .NET Framework"
      • -
      • Open source! 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
      • +
      • Launched in 2016, Successor to .NET Framework
      • +
      • Open source
      • +
      • Cross-platform (Linux, Mac, Windows)
      • +
      • Current version 9.0 launched in 2024
    • +
    • We will be using .NET Core as the .NET Framework is considered legacy
    - -
  • -

    Base Class Library (BCL)

    +
  • +
    +

    Common Language Infrastructure (CLI)

    +
    +
      -
    • 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
    • +
    • Common Language Infrastructure (CLI) is a standardized specification that decribes how different high-level langauges (like C#) can be run on different platforms without having to be rewritten
    • +
    • both versions of .NET are implementations of the CLI
    • +
    • Another implementation is the free and open-source Mono project +
        +
      • Used by the Unity game engine and the MonoGame framework
    -

    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

    -

    -

    Source: 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:

    -

    -

    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

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

    +
    +
    +
    +
    +

    Base Class Library (BCL)

    +
      +
    • Base Class Library (BCL) is a set of libraries that every .NET implementation uses, mostly under the System namespace
    • +
    • Consists of common tools like classes and value types that you will need 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;
       
      -

      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

      -

      -

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

      -

      -

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

      -

      -

      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

    +

    Assignments about this topic can be found here