object obj = "Hello";
// is keyword
if (obj is string str1)
{
Console.WriteLine(str1);
}
// as keyword
string str2 = obj as string;
if (str2 != null)
{
Console.WriteLine(str2);
}
In the code above, the local variable is declared with the 'is' keyword, but is there any difference in performance with the 'as' keyword?
I wonder if there is a performance difference related to casting and null checking. (Aside from local scope differences of str1 and str2 variables)