mediumIEnumerable vs IQueryable
IQueryable<Order> q = db.Orders;
var result = q.Where(o => o.Total > 100)
.AsEnumerable()
.Where(o => o.Notes.Contains("urgent"))
.ToList();
Read the full question →easyforeach and iterators
var items = new List<string> { "a", "b" };
foreach (var item in items)
{
item = item.ToUpper();
}
Read the full question →easyvar and type inference
var n = 3.0;
Read the full question →easy
var value = null;
Read the full question →easy
var nums = new[] { 1, 2, 3, 4 };
var result = nums.Where(n => n % 2 == 0).Select(n => n * 10);
Console.WriteLine(string.Join(",", result));
Read the full question →easynullable types
int? x = 5;
Console.WriteLine(x.GetType());
Read the full question →easyvalue vs reference types
struct Point { public int X; }
var a = new Point { X = 5 };
var b = a;
b.X = 99;
Console.WriteLine(a.X);
Console.WriteLine(b.X);
Read the full question →easystring interpolation
double rate = 0.5;
Console.WriteLine($"{rate:P0}");
Read the full question →easyvalue vs reference types
void Print(in int x) => Console.WriteLine(x);
Read the full question →easyvalue vs reference types
int[] arr = { 1, 2, 3 };
int[] copy = arr;
copy[0] = 42;
Console.WriteLine(arr[0]);
Read the full question →easyasync await basics
async Task<int> LoadAsync()
{
var data = await FetchAsync();
return data.Length;
}
Read the full question →easyLINQ Where and Select
var query = source.Where(x => x > 0).Select(x => Transform(x));
// query is never iterated
Read the full question →easyforeach and iterators
foreach (var item in collection) { /* ... */ }
Read the full question →easyasync await basics
async void Fire()
{
await Task.Delay(10);
throw new InvalidOperationException();
}
Read the full question →easyexceptions try catch
int Run()
{
try
{
throw new InvalidOperationException();
}
catch (InvalidOperationException)
{
return 1;
}
finally
{
Console.WriteLine("cleanup");
}
}
Read the full question →easyList and Dictionary
var scores = new Dictionary<string, int>();
// ...
Read the full question →easyexceptions try catch
try { DoWork(); }
catch (Exception ex)
{
Log(ex);
throw; // vs. throw ex;
}
Read the full question →easyusing statement and disposal
using (var a = new Res("A"))
using (var b = new Res("B"))
{
// work
}
Read the full question →easygenerics basics
static void Print(IEnumerable<object> items) { }
List<string> names = new() { "a", "b" };
Print(names);
Read the full question →mediumcustom equality IComparer
var d = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
d["Hello"] = 1;
d["HELLO"] = 2;
Console.WriteLine(d.Count + " " + d.Keys.First());
Read the full question →