Complete the code to check if the object is an integer using pattern matching.
if (obj is [1] number) { Console.WriteLine($"Number: {number}"); }
The is keyword with pattern matching checks if obj is of type int and assigns it to number.
Complete the code to check if the object is a string and get its length.
if (obj is [1] text) { Console.WriteLine($"Length: {text.Length}"); }
char instead of string.Length on a non-string type.The is pattern matching checks if obj is a string and assigns it to text, allowing access to Length.
Fix the error in the pattern matching to check if obj is a double.
if (obj is [1] value) { Console.WriteLine($"Double value: {value}"); }
float which is single precision.decimal which is a different numeric type.The correct type for a double-precision floating-point number is double. Using double in the pattern matching allows correct type checking.
Fill both blanks to check if obj is a string and print its uppercase form.
if (obj is [1] text) { Console.WriteLine(text.[2]()); }
int instead of string.Length instead of ToUpper.The first blank must be string to match the type. The second blank is the method ToUpper to convert text to uppercase.
Fill all three blanks to create a pattern matching that checks if obj is a list of integers and prints the count.
if (obj is [1] list) { Console.WriteLine($"Count: {list.[2]"); foreach (var item in list) { Console.WriteLine(item.[3]); } }
Length instead of Count for lists.List<int>.The first blank is the type List<int> to check for a list of integers. The second blank is Count to get the number of items. The third blank is ToString() to convert each item to text for printing.