C# and .NET Basics

Spencer Schneidenbach

Spencer Schneidenbach

Aviron Software, Microsoft MVP
5 hours, 48 minutes CC
C# and .NET Basics

Course Description

Learn C# — one of the top 5 programming languages on GitHub! Explore the C# language while working with common .NET tools. Learn to create abstract and concrete classes, use inheritance and interfaces, and work with extension methods. Leverage the power of LINQ while querying and manipulating collections of objects. Use common libraries to work with files, streams, asynchronous programming, and JSON data.

This course and others like it are available as part of our Frontend Masters video subscription.

Preview
Close

Course Details

Published: November 4, 2024

Learning Paths

Learn Straight from the Experts Who Shape the Modern Web

Your Path to Senior Developer and Beyond
  • 200+ In-depth courses
  • 18 Learning Paths
  • Industry Leading Experts
  • Live Interactive Workshops
Get Unlimited Access Now

Table of Contents

Introduction

Section Duration: 10 minutes
  • Introduction
    Spencer Schneidenbach introduces himself and provides an overview of the course on C Sharp and .NET. He also discusses the evolution of .NET, its benefits, and its relevance in the current market.

Introduction to .NET

Section Duration: 31 minutes
  • Brief History of .NET
    Spencer explains the evolution of .NET, including the introduction of C# and VB.NET, the .NET Framework, WinForms, and WebForms. He also touches on the challenges faced by .NET in the past, such as being Windows-only and closed source, and how these issues were addressed with the introduction of .NET Core, which is cross-platform and open source.
  • .NET Terms & Use Cases
    Spencer explains that .NET is a brand that encompasses different components, such as the Common Language Runtime (CLR) and programming languages like C#. He also discusses use cases such as AOT compilation, cross-platform development with Xamarin and .NET Maui, Windows-specific frameworks like Windows Forms and Windows Presentation Foundation, cloud and microservices development with Azure, and game development with Unity and Godot.
  • .NET Tooling
    Spencer provides an overview of the tools used in .NET development such as the .NET CLI, Visual Studio Code, and the C-sharp dev kit extension. He also mentions the NuGet gallery extension for Visual Studio Code and briefly discusses the use of Visual Studio for .NET development.
  • Setup .NET CLI
    Spencer demonstrates how to create a new console application using the .NET CLI and explores the generated files and folders. He also explains the purpose of the solution file, the project file, and briefly mentions the option to use a program.main style program instead of top-level statements.

C# Language

Section Duration: 1 hour, 51 minutes
  • CSharp Syntax Overview
    Spencer discusses the basics of C Sharp syntax. He explains the use of curly braces to denote blocks of code and the importance of using semicolons to end statements. He also mentions the use of comments and the case sensitivity of C Sharp language. Spencer recommends referring to the Microsoft documentation for more detailed information on C Sharp syntax.
  • Variables
    Spencer explains that variables are a way to store data in a specific scope. Spencer covers the use of the "var" keyword for implicitly typed variables, the "const" keyword for constant values, and the difference between value types and reference types. He also touches on the scope and visibility of variables.
  • Methods
    Spencer discusses methods in C# which are ways of encapsulating logic and performing reusable tasks. Spencer covers the structure of a method, including access modifiers, return types, method names, and parameters. He also demonstrates how to declare and use methods with different signatures, as well as how to declare void methods that do not return a value.
  • CSharp Built-in Types
    Spencer discusses various built-in types in C Sharp. He cover types such as int, string, bool, char, byte, long, float, double, decimal, DateTime, arrays, enums, tuples, null, and void. Spencer explains the purpose and usage of each type and provides examples to illustrate their usage. He also answer questions from the audience regarding enums and console output.
  • Strings
    Spencer discusses various methods and techniques for declaring and manipulating strings in C#. He also explains important string methods like IsNullOrEmpty, IsNullOrWhiteSpace, Equals, Length, StartsWith, EndsWith, Trim, Substring, and Replace. Additionally, they mention the use of the StringBuilder class for more efficient string manipulation.
  • Control Flow
    Spencer if statements, if-else statements, cascading if statements, switch statements, for loops, while loops, do-while loops, and for-each loops. He also mentions the use of break and continue statements to exit or skip iterations in a loop.
  • Exception Handling
    Spencer introduces exceptions as errors thrown by the runtime. He demonstrates how to handle exceptions using a try-catch block and explains the purpose of the try and catch sections. He also discusses the finally block, which always executes regardless of whether an exception is caught or not.
  • Pattern Matching
    Spencer explains that pattern matching is useful when dealing with objects of different types and demonstrates how to use the "is" operator to check if a value is of a specific type. He also briefly mentions other types of pattern matching, such as checking for specific content or properties, and mentions that the IDE provides suggestions for using pattern matching.
  • Operators
    Spencer discusses using operators to create binary statements that can compare values, change values, or perform mathematical operations. This lesson covers various operators such as addition, subtraction, multiplication, division, modulus, increment, decrement, relational, logical, and assignment operators.
  • Conversion
    Spencer explains that C# will automatically convert certain types in limited circumstances. He covers implicit and explicit conversions, as well as the use of parse methods and the convert class for converting between different types.

Types, Classes, & Structures

Section Duration: 1 hour, 25 minutes
  • Types
    Spencer explains the differences between value types and reference types. He also explains the concept of nullability and how reference types can have a value of null, which can lead to null reference exceptions. He briefly mentions the concept of boxing and unboxing, which involves converting a value type to a reference type and vice versa.
  • Classes
    Spencer introduces the concept of classes in object-oriented programming. He demonstrates how to declare fields and properties in a class and explains the difference between them. He also shows how to control the accessibility of properties and how to create computed properties.
  • Class Constructor
    Spencer demonstrates how constructors are used to instantiate objects and set initial values for their properties. He also discusses the use of default values, multiple constructors, object initializer syntax, and validating data in constructors. He briefly mentions the concept of referential equality and how it can be overridden using the equals method or interfaces.
  • Structs & Records
    Spencer discusses structs in C# which are specialized value types that can be used to declare objects that are instantiated and live in the stack. He compares structs to classes and introduces the concept of record types, which are reference types with struct-like properties. Spencer demonstrates the use of records and discusses their implications in terms of structural equality and data processing.
  • Inheritance
    Spencer explains that objects can inherit properties and behaviors from other objects, and demonstrates how to declare a class that inherits from another class. He also demonstrates adding accessibility modifiers such as protected, private, and public, and shows how they can be used to control access to methods and properties within a class hierarchy.
  • Sealed vs. Virtual
    Spencer explains the difference between the sealed and virtual keywords. He demonstrates how to use the virtual keyword and shows an example of overriding a method in a derived class. He also mentions the use of the "base" keyword to refer to the base class and how to seal a method to prevent further overriding in certain derived classes.
  • Abstract Classes
    Spencer discusses abstract classes in object-oriented programming. He explains that abstract classes are meant to be inherited from and cannot be instantiated directly. Spencer also shares their opinion on the use of inheritance, cautioning against overusing it and suggesting alternative approaches to modeling business problems.
  • Interfaces
    Spencer explains interfaces as similar to micro abstract classes with no inheritance hierarchy. He demonstrates how to declare and implement an interface in code and discusses the use cases and advantages of interfaces over abstract classes.
  • Extension Methods in CSharp
    Spencer introduces the concept of extension methods which allow developers to add behavior to existing classes without actually extending those classes. He demonstrates how to define and use extension methods using examples with the string class.

Collections, Generics, & Linq

Section Duration: 53 minutes
  • Generics
    Spencer introduces the concept of generics and explains that they are a way of implementing polymorphism. Examples and explanations of how to create generic classes and methods, as well as how to constrain the type of a generic are provided.
  • Arrays vs. Collections
    Spencer explains that arrays cannot be resized or have elements added or removed, and that if more space is needed, a new array must be created. He also introduces the IEnumerable interface, a generic collection type that allows for iterating over collections and performing actions on each item.
  • Lists
    Spencer discusses lists which are a common class for collections in .NET that provide flexibility in creating lists of specific types. He covers methods such as add, remove, and add range that can be used with lists. He also briefly mentions other collection types like hash set, dictionary, immutable array, queue, and stack.
  • Lambda Expressions
    Spencer introduces the concept of Lambda expressions or Lambda functions. He explains that Lambda functions are a shorthand way of defining small functions and demonstrates how to define and use Lambda functions in C#. Spencer also discusses the use of specialized types like func and action to define the shape of functions.
  • Introduction to LINQ
    Spencer introduces the concept of LINQ (Language Integrated Query) in .NET. He explains how LINQ allows for easy querying and manipulation of collections of objects. He also discusses the lazy evaluation nature of LINQ and provides examples of how to materialize the results.
  • LINQ: Selecting, Ordering, & Filtering
    Spencer demonstrates creating a collection of employees and then shows how to use LINQ methods such as Select, Where, OrderBy, and Aggregate to manipulate and query the collection. He also explains the difference between methods like First, Single, and SingleOrDefault, and provides examples of how to use them. Additionally, he mentions other LINQ methods like Sum, Max, Min, and Average for performing calculations on collections of numbers.
  • LINQ: GroupBy & SelectMany
    Spencer demonstrates how to use the Distinct, GroupBy, SelectMany, and Join methods in C#. He shows how to use the Distinct method to get a unique list of items, the GroupBy method to group items together based on a specific value, the SelectMany method to flatten multiple collections into one, and briefly mentions the Join method for combining two collections based on a common value.

Common Libraries and Advanced Topics

Section Duration: 54 minutes
  • Asynchronous Programming
    Spencer covers the concept of asynchronous programming and how it enables responsive and scalable applications. Spencer demonstrates the use of the async and await keywords to make asynchronous method calls and explains best practices for using async methods. He also discusses potential issues such as deadlocks and resource exhaustion.
  • Dispose Pattern
    Spencer explains the concept of the Dispose pattern in C#. He discusses how resources, such as database connections, need to be explicitly disposed of to prevent them from being kept open indefinitely. He introduces the IDisposable interface and demonstrates how to implement it to release unmanaged resources. Spencer also explains the `using` keyword, which provides a convenient way to automatically dispose of resources at the end of a code block.
  • Streams
    Spencer introduces the concept of streams as an abstraction of a sequence of bytes. He explains that streams are commonly used for handling input and output in .NET and provides examples of different types of streams, such as file streams and memory streams.
  • File APIs
    Spencer demonstrates how to read and write files directly from disk using the File class, and the usage of methods such as `File.ReadAllText()`, `File.ReadAllLines()`, and `File.ReadAllBytes()`. He also mentions the FileInfo class for obtaining metadata about a file, the directory class for creating directories, and the Path class for manipulating file paths.
  • Making HTTP Requests
    Spencer discusses how to make HTTP requests using the HTTP client in C#. He explains the different methods available, such as GetStringAsync and GetAsync, and how to use the HTTP request message to specify the HTTP verb, URL, headers, and body of the request.
  • Working with JSON
    Spencer discusses the importance of JSON in data transformation for the web and compares two major JSON libraries in .NET: Newtonsoft.Json and System.Text.Json. He explains the process of serializing and deserializing objects to and from JSON and provides advice on which library to use based on the system being used.
  • Reflection and Attributes
    Spencer introduces reflection which allows developers to inspect and manipulate type data at runtime, such as getting the type of an object, accessing its properties, and changing their values. Spencer also briefly mentions the use of attributes, which are metadata that can be added to code to provide additional information about how it should behave.

Wrapping Up

Section Duration: 1 minute
  • Wrapping Up
    Spencer wraps up the course by providing a brief overview of the material covered, including the dotnet core CLI, VS code, and various aspects of C Sharp syntax, including default types, classes, interfaces, and inheritance. He also discusses .NET specific features like LINQ for manipulating collections and common APIs such as file handling, HTTP client, and JSON conversion.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now