since C# 7, the next is possible:
object greeting = "Hello, World!";
if (greeting is string message)
{
Console.WriteLine(message.ToLower()); // Output: hello, world!
}
see more examples here: https://medium.com/@nirajranasinghe/pattern-matching-in-c-fcee69929776#:~:text=Understanding%20Pattern%20Matching%20in%20C%23,var%2C%20List%20and%20discard%20patterns.