Store Different Data Types Value in Array
In this blog, I want to explain how to store Different Data Types Value in Array?
Array
Array means collection of similar Data Types or Store Collection of similar Data Types Value in Array.
Ex:
We declare or Create integer type array as "no". We can store only integer value not like string,bool etc.
- int[] no = new int[2];
- no[0] = 9080;
- no[1] = 8090;
We want to store any data type value other than int then show error as
But we can store different data type value in array as;
- namespace Array
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool b = true;
- object[] obj = new object[3];
- obj[0] = 1;
- obj[1] = "Vishu";
- obj[2] = b;
- Console.WriteLine("value of Array 0 as" + " " + obj[0] + " ");
- Console.WriteLine();
- Console.WriteLine("and value of array 1 as" + " " + obj[1] + "");
- Console.WriteLine();
- Console.WriteLine("and value of array 2 as" + " " + obj[2] + "");
- Console.ReadLine();
- }
- }
- }
Object
Object is Reference Type , you can assign any value type and reference type variable to object data type.
Output