Complete the code to declare a dynamic variable.
dynamic value = [1];The dynamic keyword allows the variable to hold any type. Here, assigning the integer 10 is valid.
Complete the code to access the length property on a dynamic variable.
dynamic obj = "hello"; int length = obj.[1];
The Length property returns the number of characters in a string. When using dynamic, this is resolved at runtime.
Fix the error in the dynamic method call.
dynamic obj = 123; string text = obj.[1]();
The method ToString() converts the integer to its string representation. It is case-sensitive and must be capitalized.
Fill both blanks to create a dictionary with dynamic keys and values.
var dict = new Dictionary<[1], [2]>();
Using dynamic for both key and value types allows runtime type resolution for dictionary entries.
Fill all three blanks to create a dynamic method call with runtime type resolution.
dynamic obj = GetDynamicObject(); var result = obj.[1]([2]: [3]);
The method Calculate is called with a named parameter value set to 42. This call is resolved at runtime due to dynamic.