Working with Variable: Storing Any Type of Object
Learn how to use C#'s object and dynamic types to store mixed data, how casting is required to access object members.
We'll cover the following...
We'll cover the following...
A special type named object can store any type of data, but its flexibility comes at the cost of messier code and possibly poor performance. Because of those two reasons, we should avoid it whenever possible.
Using the object type
The following steps show us how to use object types if we need to use them:
Step 1: Use your preferred code editor to add a new "Console App/console" project named Variables to the Chapter02 workspace/solution.
Select
Variablesas the activeOmniSharpproject if you use Visual Studio Code. When you see the pop-up warning message ...