Enterprise Web Development C# Summary Samenvatting HoGent
28 views 0 purchase
Course
Enterprise Web Development C#
Institution
Hogeschool Gent (HoGent)
Summary for the course Enterprise Web Development C#, found in the third year of applied Computer Sciences
Samenvatting van het vak Enterprise Web Development C#, in het 3de bachelor van het traject Toegepaste Informatica (TI)
Enterprise Web Development C#
• GitHub website cursus
∘ Shift + vraagteken voor hulp in slides
Evaluatie
• 100% exam in the examination period on your own device
• Open internet maar zonder AI tools, passive internet gebruiker
• Implement parts of a larger solution
• If the code does not compile a.ka. Build Errors = 0/20
∘ Catchup exam is done orally via Teams, only possible given a valid reason
• Je mag andere editors zoals Rider gebruiken, zolang het geen AI tools bevat
4
, CHAPTER 1: INTRODUCTION TO THE .NET ECOSYSTEM
Chapter 1: Introduction To The .NET Ecosystem
.NET Explained
.NET: The Ecosystem
• Languages
∘ C#
∘ F#
∘ Visual Basic
• Libraries
∘ Base Class Library
∘ 3rd party
∘ Provided by the NuGet package manager
• Compilers
∘ Roslyn
■ Compiles to Intermediate Language Code (=bytecode) to be run on the CLR (=JVM)
∘ RyuJIT
■ Compiles to native code
• Runtimes
∘ Common Language Runtime
■ An Application Virtual Machine
■ Compiles the Intermediate Language Code Just In Time to Machine Code
Deveopment flow
C# code gets compiled using Roslyn into Intermediate Language Code which is stored in Dynamic Link Libraries
(DLLs), which can then be executed using the Common Language Runtime (CLR). Finally the CLR compiles
the code Just In Time (JIT) to machine code
Figure 1: Development flow
History
• .NET Framework
• .NET Core
• .NET Standard
Figure 2: History of .NET
5
,Hello world CHAPTER 1: INTRODUCTION TO THE .NET ECOSYSTEM
Hello world
Your first application
• Information about the SDK dotnet --info
• Get a list of all possible starter templates dotnet new list
• Create a new console application dotnet new console -o NameApp -f net6.0 --use-program-main
The --use-program-main flag disables top-level statements
• Build the application dotnet build
• Build and run the application dotnet run
When running this command dotnet build is implicitly implied.
Class libraries
In C#, a class library is a collection of classes, interfaces, structs, enums, and other types of .NET code that
can be reused in multiple applications. It is essentially a container for reusable code that provides a way to
encapsulate and organize functionality that can be used across different C# projects or applications.
Class libraries are typically compiled into DLL (Dynamic Link Library) files, which can be referenced by other
C# projects or assemblies. They can’t be run by themselves.
Op het examen zijn er ook gedeelde class libraries die aan elkaar gelinked zullen zijn
Creating a Class Library
1. Create a new folder hello-class-libraries with a src folder inside.
mkdir hello -class - libraries
cd hello -class - libraries
mkdir src
cd src
2. Create a new Console Application
dotnet new console -o App -f net6 .0
3. Create a Class Library
dotnet new classlib -o Domain -f net6 .0
Linking a Class Library
We want to use Classes from the Domain project in the App project so:
1. Execute the following command in the src folder (the root folder) to link the Domain Class Library to
the Application.
Without a explicit reference you cannot use any classes defined in the Domain.csproj class library from
the Console Application.
6
,GIT CHAPTER 1: INTRODUCTION TO THE .NET ECOSYSTEM
Referencing a Class Library
In plaats van using Domain; bij de imports, kunnen we ook namespace Domain ... rond onze klasse
zetten.
GIT
Repository structure
Standard folder structure:
• Projectname (repository)
• .gitignore (in the root folder)
• readme.md (information about the repository)
• src/
∘ project1/
■ Files for project1
∘ classlibrary1/
■ Files for classlibrary1
∘…
• tests
∘ Same as src/ but for tests
7
, CHAPTER 3: MODEL & UNIT TESTING (SOLVING THE PROBLEM DOMAIN)
Chapter 3: Model & Unit Testing (Solving The Problem Domai
Classes
Members of a class
• Fields (=attributes)
• Methods
• Constructor - destructor
• Properties
Access modifiers for members
• public
∘ Accessible from everywhere
• private
∘ Only accessible from within the class
private is the default
• internal
∘ Only accessible within the same assembly
■ An assembly = one unit of deployment, version control, …
• protected
∘ Only accessible within the class and all classes that inherit from this class
In Java: also accessible in same package, not in C#!
• protected internal
∘ Combination of protected and internal
Access modifiers for classes
Classes, structs or records directly declared in a namespace can be public or internal (default)
Directly declared in a namespace = not nested in another class or struct
Nested classes or structs in structs can be declared public , internal or private .
Nested classes or structs in classes can be declared all of the previous ones ( public , private , protected
, internal or protected internal ).
The default for nested classes or structs is private .
Derived classes andrecords can’t have greater accessibility than their base types
Fields
[modifier] datatype variableName
• Always private
• Can be static
∘ Linked to the class and not to an instance
∘ Static members only exist once per class
• Naming convention: _camelCase
public class BankAccount
{
private string _accountNumber ;
private decimal _balance ;
}
8
,Classes CHAPTER 3: MODEL & UNIT TESTING (SOLVING THE PROBLEM DOMAIN)
Constants
• Use the keyword const
• Must be initialized when declared
• Value can never change
• Implicit static, i.e. doesn’t have the keyword
• Naming convention: PascalCase
public class BankAccount
{
public const decimal WithdrawCost = 0.25M;
}
Readonly
• Use the keyword readonly
• Can only be assigned a value once
∘ At declaration OR in the constructor
• Not required at declaration <> const
public class BankAccount
{
private readonly string _accountNumber ;
private decimal _balance ;
}
Methods
[modifier] return_type MethodName([parameters]) { … }
• Can be static
• Naming convention: PascalCase
public class BankAccount
{
private readonly string _accountNumber ;
private decimal _balance ;
public void Deposit ( decimal amount )
{
throw new NotImplementedException ();
}
}
Parameter list
• Seperated by a comma
• Have a type and name (camelCase)
• Can be optional
∘ Can have a default value
∘ No value is required when calling the method
∘ Last in the list
public void ExampleMethod (int required , int optionalInt = 10)
{
throw new NotImplementedException ();
}
// Calling this method
9
, Classes CHAPTER 3: MODEL & UNIT TESTING (SOLVING THE PROBLEM DOMAIN)
ExampleMethod (5); // optionalInt will be 10
ExampleMethod (5, 8); // optionalInt will be 8
Named arguments Not every optional parameter may have a value, only specific optional parameter can be
passed to a function using named arguments
public void ExampleMethod (int required , string optionalStr = " default value ",
int optionalInt = 10)
{
throw new NotImplementedException ();
}
ExampleMethod (5, optionalInt : 8);
Passing parameters Parameters can be passed in 3 ways:
• Value parameters
public void Test1 (int x)
{
x += 1;
}
int i = 0;
Test1(i); // i is still 0
• ref parameters
∘ Must write ref when declaring and passing value
∘ Passed variable must be initialized
∘ Every change to the variable’s value will be reflected to the ref parameter
public void Test2 (ref int x)
{
x +=1;
}
int i = 0;
Test2(ref i); // i now has value 1
• out parameters
∘ Must write out when declaring and passing value
∘ Passed variable must not be initialized
∘ The method must assign a value to the out parameter
public void Test3 (out int 3)
{
x = 10;
}
int i = 0;
Test3(out i); // i has now value 10
Passing objects as value parameters, copies the references.
• You can change properties and fields of the object, but not the actual variable’s value. That is only
possible with the ref keyword.
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller TomDeBakker. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $5.90. You're not tied to anything after your purchase.