Working with Variable: Storing Any Type of Object
Explore how to use the object and dynamic types in C# to store any type of data. Understand the trade-offs in flexibility, performance, and code safety when using these types. Learn to work with casting, runtime behavior, and how dynamic impacts development tools like IntelliSense.
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 ...