Complete the code to declare a variable that can hold any type of value.
object [1] = 42;
In C#, object is the universal base type. You can name the variable anything, but obj is a common choice.
Complete the code to assign a string value to an object variable.
object obj = [1];Strings in C# are enclosed in double quotes. Assigning a string literal to an object variable is allowed.
Fix the error in the code by completing the cast from object to string.
object obj = "test"; string s = ([1])obj;
To convert an object holding a string back to a string, you must cast it to string.
Fill both blanks to create an object array and assign different types of values.
object[] arr = new object[] { [1], [2] };An object array can hold any types. Here, a string and an integer are assigned.
Fill all three blanks to create a method that returns an object and assigns different types inside.
public object GetValue(int choice) {
return choice switch {
1 => [1],
2 => [2],
_ => [3]
};
}The method returns different types as objects based on the input choice: a string, an integer, or a boolean.