This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Gadget | |
{ | |
public Gadget(int id, string name) | |
{ | |
this.Id = id; | |
this.Name = name; | |
} | |
public int Id { get; } | |
public string Name { get; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Gadget | |
{ | |
public Gadget(int id, string name) | |
{ | |
this.id = id; | |
this.name = name; | |
} | |
private readonly int id; | |
public int Id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using static System.Console; | |
class Program | |
{ | |
public void Main() | |
{ | |
WriteLine("Hello, World!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void UsingSimpleArrays() | |
{ | |
Console.WriteLine(nameof(UsingSimpleArrays)); | |
for (int i = 0; i < 20; i++) | |
{ | |
LocalUseOfArray(i); | |
} | |
Console.WriteLine(); | |
Console.WriteLine(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsafe private static void ShowAddress(string name, int[] item) | |
{ | |
fixed (int* addr = item) | |
{ | |
Console.Write($"\t0x{(ulong)addr:X}"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void UsingSimpleArraysWithGC() | |
{ | |
Console.WriteLine(nameof(UsingSimpleArraysWithGC)); | |
for (int i = 0; i < 20; i++) | |
{ | |
GC.Collect(0); | |
LocalUseOfArray(i); | |
} | |
Console.WriteLine(); | |
Console.WriteLine(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void LocalUseOfSharedPool(int i) | |
{ | |
int[] arr = ArrayPool<int>.Shared.Rent(ARRAYSIZE); | |
ShowAddress($"simple array {i}", arr); | |
FillTheArray(arr); | |
UseTheArray(arr); | |
ArrayPool<int>.Shared.Return(arr); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<T> Where<T>(this IEnumerable<T> source, Func<T, bool> predicate) | |
{ | |
if (source == null) throw new ArgumentNullException(nameof(source)); | |
if (predicate == null) throw new ArgumentNullException(nameof(predicate)); | |
foreach (T item in source) | |
{ | |
if (predicate(item)) | |
{ | |
yield return item; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<T> Where<T>(this IEnumerable<T> source, Func<T, bool> predicate) | |
{ | |
if (source == null) throw new ArgumentNullException(nameof(source)); | |
if (predicate == null) throw new ArgumentNullException(nameof(predicate)); | |
return WhereImpl(source, predicate); | |
} | |
private static IEnumerable<T> WhereImpl<T>(IEnumerable<T> source, Func<T, bool> predicate) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<T> Where<T>(this IEnumerable<T> source, Func<T, bool> predicate) | |
{ | |
if (source == null) throw new ArgumentNullException(nameof(source)); | |
if (predicate == null) throw new ArgumentNullException(nameof(predicate)); | |
return Iterator(); | |
IEnumerable<T> Iterator() | |
{ | |
foreach (T item in source) |