24
loading...
This website collects cookies to deliver better user experience
static bool IsFirstOfTheMonth(DateTime date) => date is { Day: 1 };
private static (bool isValid, string reason) Validate(Note note)
{
if (note == null)
throw new ArgumentNullException(nameof(note));
if (note.Title.Length < 5 || note.Title.Length > 50)
return (false, "Title should be 5 to 50 char long");
if (note.Content == null)
return (false, "Content is required");
return (true, "");
}
private static (bool isValid, string reason) Validate(Note note)
=> note switch
{
{ Title.Length: < 5 or > 50 } => (false, "Title should be 5 to 50 char long"),
{ Content: null } => (false, "Content is required"),
null => throw new ArgumentNullException(nameof(note)),
_ => (true, "")
};
try
{
//...
}
catch (NpgsqlException ex) when (ex is {Code: "42P01"})
{
//...
}
if (person is Student { Address.CountryCode: "PT" })
person is Student ({ Address.CountryCode: "PT" } or { Address.CountryCode: "ES" }) and { Age: < 20}