Pawel Lukasik
.net dev
int binary = 0b111000;
int bcd = 0b1110_0001;
//....
int value = 123_1_2_11;
if (int.TryParse("1977", out int year))
{
Console.WriteLine($"Ok! year: {year}");
}
if (int.TryParse("1977", out _))
{
Console.WriteLine("Ok. But now year {_}");
}
switch (character)
{
case DarthVader dv:
dv.Noooooooo();
break;
case PrincessLeia pl:
pl.Say();
break;
case BobaFett b when b.Episode == 5:
b.HuntHanSolo();
break;
case BobaFett b:
b.DoNothing();
break;
case R2D2 r2d2:
r2d2.Beep();
break;
}
var t = (a: "ala", ma: "kota");
Console.WriteLine(t.a);
Console.WriteLine(t.ma);
var (a, ma) = t;
Console.WriteLine(a);
Console.WriteLine(ma);
var user = (firstName: "Paweł", lastName: "Łukasik");
var (firstname, _) = user;
string LocalFunction()
{
string LocalFunction2() => "function";
return "Local" + LocalFunction2();
}
Console.WriteLine(LocalFunction());
public static ref Point GetHalfPoint()
{
return ref _p;
}
//....
ref var p1 = ref GetHalfPoint();
public string Name
{
get => _name;
set => _name = value;
}
ExpressionBodiedFunctionDemo(string name) => Name = name;
~ExpressionBodiedFunctionDemo() => Name = null;
public void NewWay(string param1, int? param2)
{
P1 = param1 ?? throw new ArgumentNullException(nameof(param1));
P2 = param2 ?? throw new ArgumentNullException(nameof(param2));
}
class Person
{
public string FirstName; // Not null
public string? MiddleName; // May be null
public string LastName; // Not null
}
foreach await (string s in asyncStream)
{
//...
}
using await (var transaction = connection.BeginTransaction())
{
// do important work
transaction.Commit();
}
class Person(string First, string Last);
https://www.erikheemskerk.nl/c-sharp-7-2-and-8-0-uncertainty-awesomeness/
extension CustomerExt extends Customer {
//methods and properties go here
}
public interface ILogger
{
void Log(LogLevel level, string message);
void Log(LogLevel level, string format, params object[] arguments)
{
Log(level, string.Format(format, arguments));
}
void Debug(string message)
{
Log(LogLevel.Debug, message);
}
void Debug(string format, params object[] arguments)
{
Log(LogLevel.Debug, string.Format(format, arguments));
}
}
https://www.erikheemskerk.nl/c-sharp-7-2-and-8-0-uncertainty-awesomeness/
;)
@pawel_lukasik
By Pawel Lukasik