Monday, June 23, 2025 18:35

Table of contents >> Introduction > Object variable type

Object variable type

Object variable type is a special type, the parent of all other types in the .NET Framework. It can accept values from any other type in C#, and we declare it using the word object

In the following example you can see how we can assign any type to an object variable type:

// Declare some variables 
object container1 = 5; 
object container2 = "Five";

// Print the results on the console 
Console.WriteLine("The value of container1 is: " + container1); 
Console.WriteLine("The value of container2 is: " + container2);
Console.Read();

And the output would be:

object variable type

As you can notice, the object variable can be very versatile, and we can use it as a universal data container.

The concepts explained in this lesson are also shown visually as part of the following video:

Tags: , ,

Leave a Reply