fix lecture 12-15

main
borb 2 weeks ago
parent 88c8c953c6
commit 76b49a6af8

File diff suppressed because one or more lines are too long

@ -217,15 +217,15 @@ The following reads the first 20 characters of a file and prints them to the con
```csharp
string path = @"C:\Users\Public\TestFolder\TestFile.txt";
int nOfBytesToPrint = 20;
byte[] byteArray = new byte[nOfBytesToPrint];
int numberOfBytesToPrint = 20;
byte[] byteArray = new byte[numberOfBytesToPrint];
if (!File.Exists(path))
Console.WriteLine($"The file {path} does not exist.");
else
using (FileStream fs = File.OpenRead(path))
{
fs.Read(byteArray, 0, nOfBytesToPrint);
fs.Read(byteArray, 0, numberOfBytesToPrint);
};
// No need to close the file since it was handled inside of a using block

File diff suppressed because one or more lines are too long

@ -47,32 +47,30 @@ class Program
### Multiple type parameters
Generic classes can receive multiple types as parameters:
```csharp
class CustomContainer<T1, T2, T3>
{
public T1 First { get; set; }
public T2 Second { get; set; }
public T3 Third { get; set; }
}
class Program
{
static void Main(string[] args)
* Generic classes can receive multiple types as parameters:
```csharp
class CustomContainer<T1, T2, T3>
{
CustomContainer<int, string, DateTime> container
= new CustomContainer<int, string, DateTime>();
container.First = 10;
container.Second = "Testing.";
container.Third = DateTime.Now;
public T1 First { get; set; }
public T2 Second { get; set; }
public T3 Third { get; set; }
}
}
```
class Program
{
static void Main(string[] args)
{
CustomContainer<int, string, DateTime> container
= new CustomContainer<int, string, DateTime>();
container.First = 10;
container.Second = "Testing.";
container.Third = DateTime.Now;
}
}
```
### Creating a generic Method
```csharp
void GenericMethodExample<T>(T value)
{
Console.WriteLine
@ -83,7 +81,7 @@ GenericMethodExample<string>("ABC");
![](imgs/13%20Generics%2C%20IEnumerable%20and%20LINQ_2.png)
* ***Note:*** You could name the generic type as anything, e.g. `<GenericType>`. It is named `<T>` by convention.
* ***Note:*** You could name the generic type as anything, e.g. `<GenericType>`. It is named `<T>` here by convention.
## Exercise 1: Initializing a populated list
<!-- _class: exercise -->

File diff suppressed because one or more lines are too long

@ -250,7 +250,7 @@ class Program
{
int waitTime = 5000;
await Task.Delay(waitTime);
// Replace this with your time consuming async functionality
// Replace above with some time-consuming async function
return new string(
$"The task took {waitTime / 1000} seconds to finish."
);
@ -260,7 +260,7 @@ class Program
Console.WriteLine("Starting operation...");
Task<string> resultTask = GetResultAsync();
Console.WriteLine("Operation has been started.");
Console.WriteLine("In the meantime, tell me something nice: ");
Console.WriteLine("In the meantime, say something nice:");
string somethingNice = Console.ReadLine();
resultTask.Wait(); // Wait for the task to complete
Console.WriteLine(resultTask.Result);
@ -280,5 +280,5 @@ class Program
## Exercise 3: Asynchronous Loading
<!-- _class: exercise -->
Re-create the exercise 2, but instead of using separate threads for "loading the data", use an asynchronous method `LoadDataAsync()`
Redo exercise 2, but instead of using separate threads for "loading the data", use an asynchronous method `LoadDataAsync()`.

File diff suppressed because one or more lines are too long

@ -69,7 +69,6 @@ A singleton implementation could look something like this:
<div markdown='1'>
```csharp
class Program
{
static void Main(string[] args)
@ -123,11 +122,9 @@ public class HomeController : Controller
## Design Patterns
* If the concepts of a singleton and dependency injection flew over your head, don't worry about it
* The important thing is to know they exist so that when they come up again in ASP.NET, you have already familiarized yourself with the terms
* Thus, understanding the logic behind ASP.NET becomes less overwhelming
* There are many more design patterns, see the material [here](https://www.c-sharpcorner.com/UploadFile/bd5be5/design-patterns-in-net/)
```csharp
public void ConfigureServices(IServiceCollection services)
{

Loading…
Cancel
Save