Skip to content

Commit 2459be0

Browse files
author
RedIsGaming
committed
update: small changes added
1 parent 322eebd commit 2459be0

File tree

3 files changed

+51
-31
lines changed

3 files changed

+51
-31
lines changed

notes_wpfw/.obsidian/workspace.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@
151151
"csharp/wpfw_deel1/week2/testen_mocks.md",
152152
"csharp/wpfw_deel1/week3/async_(en_functioneel)_programmeren.md",
153153
"csharp/wpfw_deel1/week4/orm_en_linq.md",
154-
"csharp/wpfw_deel1/week5/internet.md",
154+
"csharp/wpfw_deel1/week1/csharp.md",
155155
"csharp/wpfw_deel1/week7/specflow.md",
156156
"csharp/wpfw_deel1/week6/api.md",
157+
"csharp/wpfw_deel1/week5/internet.md",
157158
"Pasted image 20231210153422.png",
158159
"mock_result.png",
159-
"csharp/wpfw_deel1/week1/csharp.md",
160160
"Pasted image 20231209171503.png",
161161
"Pasted image 20231209171224.png",
162162
"Pasted image 20231209170921.png",

notes_wpfw/csharp/wpfw_deel1/week1/csharp.md

+32-14
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ interface IConsumer<in T> //Contravariance, in, low to high, args.
174174

175175
class Producer<T> : IProducer<T> //Covariance, return, no args.
176176
{
177-
public T Produce() => default(T);
177+
public T Produce() => default;
178178
}
179179

180180
class Consumer<T> : IConsumer<T> //Contravariance, no return, args.
@@ -214,6 +214,8 @@ public class Program
214214
215215
```
216216

217+
> Het volgende resultaat is: This contravariance returns: h.
218+
217219
## Generics and Generic Type Constraints
218220

219221
Wat zijn #generics? #Generics zijn waardes die je kan toekennen om #type-safety te garanderen. Elke letter geeft aan van welke type het moet zijn en die kun je met Generic Type Constraints beheren. De hoofdletters tussen <> zijn de generics. In dit voorbeeld kan #T voor elk mogelijk datatype gebruikt worden mits die aan de voorwaarden voldoet die je eraan geeft.
@@ -294,9 +296,9 @@ public class Program
294296
};
295297

296298
var data = new List<Initializer<float>> { initialize }; // For illustration purposes. You can do with the List whatever your want.
297-
var print = $"The following latitude/longtitude are: {initialize.Latitude} and {initialize.Longtitude}.\n";
298-
299-
Console.WriteLine(print);
299+
var print = $"The following latitude/longtitude are: {initialize.Latitude} and {initialize.Longtitude}.\n";
300+
Console.WriteLine(print);
301+
//The following latitude/longtitude are: 6.490459 and 2.640913.
300302
}
301303

302304
public static void Main() {} //Call method here between {}.
@@ -306,6 +308,8 @@ public class Program
306308
307309
```
308310

311+
> Resultaat: The following latitude/longtitude are: 6.490459 and 2.640913.
312+
309313
Omdat de eerste variabele het juiste type heeft, kunnen we hiervan een #List initializer van maken. Ook dit gaat tussen de { }. Vervolgens printen we dit op het scherm en krijg je nieuwste waarde terug. Als je de #generics datatype hier aanpast, moeten beide variabelen compatibel zijn, anders moet je een extra #generics type in de #struct zetten: #R. Mag ook anders heten.
310314

311315
## Operator Overloading
@@ -319,8 +323,7 @@ Daarnaast moet het return type overeen komen met het type die je in de #class, #
319323
320324
public struct Overloading(uint result)
321325
{
322-
public uint Result { get; } = result;
323-
326+
public uint Result { get; } = result;
324327
public static Overloading operator +(Overloading a, Overloading b) => new(a.Result - b.Result);
325328
}
326329

@@ -342,7 +345,8 @@ public class Program
342345
var a = new Overloading(6);
343346
var b = new Overloading(2);
344347
var c = a + b;
345-
Console.WriteLine($"Result after operator overloading is: {c.Result}.\n");
348+
Console.WriteLine($"Result after operator overloading is: {c.Result}.\n");
349+
//Result after operator overloading is: 4.
346350
}
347351

348352
public static void Main() {} //Call method here between {}.
@@ -352,6 +356,8 @@ public class Program
352356
353357
```
354358

359+
> Resultaat: Result after operator overloading is: 4.
360+
355361
Hier maken we een method, waarin we de #operator gaan implementeren. We maken twee impliciete variabelen aan met onze struct #Overloading . Die krijgen het type die we aan hebben gegeven in de #struct , namelijk #uint / #u32. Daarna tellen we die op en tonen we dit in de #Console. Het resultaat is niet 6 + 2 = 8, maar 6 - 2 = 4. Het return type is leidend.
356362

357363
Je kunt deze twee stukken #code uitvoeren en kijken wat het precies doet. Deed het wat je had verwacht? Roep de Operator method aan in Main en zie wat er gebeurd. Probeer eens een keer of een min in variabele c aan te passen. Krijg je een foutmelding of gaat dit goed? Wat gebeurd er wanneer je het return arithmatic operatoie aanpast? Test dit uit en zie wat er tevoorschijn komt.
@@ -404,19 +410,22 @@ public class Program
404410
{
405411
private static void ExtensionMethod()
406412
{
407-
const double devil = 333.0;
408-
var extend = devil.Extension(devil); //Extension Method call
409-
var overextend = Method.Extension(devil, devil);
410-
Console.WriteLine($"Local variable extends with value: {extend} and overextends with value: {overextend}.\n");
413+
const double DEVIL = 333.0;
414+
var extend = DEVIL.Extension(DEVIL); //Extension Method call
415+
var overextend = Method.Extension(DEVIL, DEVIL);
416+
Console.WriteLine($"Local variable extends with value: {extend} and overextends with value: {overextend}.");
417+
//Local variable extends with value: 666 and overextends with value: 666.
411418
}
412-
}
413419

414-
public static void Main() {} //Call method here between {}.
420+
public static void Main() {} //Call method here between {}.
421+
}
415422

416423
//Call this method in public static void Main() {} for it to work.
417424
418425
```
419426

427+
> Resultaat: Local variable extends with value: 666 and overextends with value: 666.
428+
420429
## Value and Reference Types, Structs
421430

422431
### #value-types
@@ -485,10 +494,19 @@ public class Program
485494
{
486495
var point = new Point(4, 6);
487496
Console.WriteLine($"Point x is: {point.X}.\nPoint y is: {point.Y}.");
488-
Console.WriteLine($"Point x is now: {point.X = 6}.\nPoint y is now: {point.Y = 4}.");
497+
Console.WriteLine($"Point x is now: {point.X = 6}.\nPoint y is now: {point.Y = 4}.");
498+
/*Point x is: 4.
499+
Point y is 6.
500+
Point x is now: 6.
501+
Point y is now: 4.*/
489502
}
490503
}
491504

492505
//No seperate method made here. You can directly call this to see the result.
493506
494507
```
508+
509+
> Resultaat: Point x is: 4.
510+
> Point y is 6.
511+
> Point x is now: 6.
512+
> Point y is now: 4.

notes_wpfw/csharp/wpfw_deel1/week3/async_(en_functioneel)_programmeren.md

+17-15
Original file line numberDiff line numberDiff line change
@@ -26,50 +26,52 @@ public class DownloadSource
2626
public async Task DownloadAsync()
2727
{
2828
Console.WriteLine("Awaiting downloads...");
29-
await Task.Delay(3000);
29+
await Task.Delay(3000); //Delay of 3 seconds.
3030
var source = new List<string> { "Downloading from Source" };
31-
var download = Enumerable.Range(0, TOTAL);
31+
var download = Enumerable.Range(0, TOTAL); //Total of 50 elements.
3232
33-
foreach (var downloads in download)
33+
foreach (var downloads in download) //Loop through the 50 elements.
3434
{
3535
var result = await Task.Run(() => source
3636
.Select((value, number) => new { Value = value, Number = number })
3737
.OrderBy(d => d.Value)
3838
.ToList());
39-
39+
40+
//Print the items from the List in the Console.
4041
result.ForEach(d =>
4142
{
4243
Console.WriteLine($"Task: {source[d.Number]} {downloads + 1}...");
43-
Task.Delay(150).Wait();
44+
Task.Delay(150).Wait(); //Wait required with a delay of 0.15 seconds.
4445
});
4546
}
4647

47-
await Task.CompletedTask;
48+
await Task.CompletedTask; //Wait for the Task to complete.
4849
}
4950

5051
public async Task SourceAsync()
5152
{
52-
await Task.Delay(1500);
53+
await Task.Delay(1500); //Delay of 1.5 seconds.
5354
var process = new List<string> { "Processing data from Source" };
54-
var download = Enumerable.Range(0, TOTAL);
55+
var download = Enumerable.Range(0, TOTAL); //Total of 50 elements.
5556
56-
foreach (var processes in download)
57+
foreach (var processes in download) //Loop through the 50 elements.
5758
{
5859
var result = await Task.Run(() => process
5960
.Select((value, number) => new { Value = value, Number = number})
6061
.OrderBy(p => p.Value)
6162
.ToList());
62-
63+
64+
//Print the items from the List in the Console.
6365
result.ForEach(p =>
6466
{
65-
var random = new Random().Next(1, TOTAL);
67+
var random = new Random().Next(1, TOTAL); //Total random from 1 to 50.
6668
Console.WriteLine($"Process: {process[p.Number]} {processes + 1} {random}MB / {random}MB...");
67-
Task.Delay(75).Wait();
69+
Task.Delay(75).Wait(); //Wait required with a delay of 0.075 seconds.
6870
});
6971
}
7072

7173
Console.WriteLine("All downloads and processes completed!!!");
72-
await Task.CompletedTask;
74+
await Task.CompletedTask; //Wait for the Task to complete.
7375
}
7476
}
7577

@@ -107,7 +109,7 @@ WhenAny //Task<Task>
107109
Yield //YieldAwaitable
108110
```
109111

110-
> Je hoeft niet alles uit je hoofd te kennen. Waarschijnlijk zul je zelf maar maximaal 3 nodig hebben. Delay, Run en CompletedTask gebruik je het meest. Maar FromResult kan handig zijn als je in een synchroon programma werkt, waarin je niet met async en #await bezig bent.
112+
> Je hoeft niet alles uit je hoofd te kennen. Waarschijnlijk zul je zelf maar maximaal 3 nodig hebben. Delay, Run en CompletedTask gebruik je het meest. Maar FromResult kan handig zijn als je in een synchroon programma werkt, waarin je niet met async en #await bezig bent. Er zijn meer methods beschikbaar wanneer je deze chaint, zoals bijvoorbeeld Wait.
111113
112114
### Running Main Program
113115

@@ -127,7 +129,7 @@ public class Program
127129

128130
```
129131

130-
> Hier roepen we de objecten aan. Nadat de downloads klaar zijn, zie je: Awaiting processes... verschijnen. Dit heeft een vertraging van 1,5 seconden.
132+
> Hier roepen we de objecten aan. Nadat de downloads klaar zijn, zie je: Awaiting processes... verschijnen. Dit heeft een vertraging van 1,5 seconden. Het is mogelijk een locale variabele aan te maken die async heet.
131133
132134
### Result Async Program
133135

0 commit comments

Comments
 (0)