Type.GetTypeArray() Method in C#


The Type.GetTypeArray() method in C# is used to get the types of the objects in the specified array.

Syntax

Following is the syntax −

public static Type[] GetTypeArray (object[] args);

The arg argument is an array of objects whose types to determine.

Example

Let us now see an example to implement the Type.GetTypeArray() method −

using System;
using System.Reflection;
public class Demo {
   public static void Main(){
      Object[] obj = new Object[5];
      obj[0] = 10.20;
      obj[1] = 20;
      obj[2] = 30;
      obj[3] = 40;
      obj[4] = "tom";
      Type[] type = Type.GetTypeArray(obj);
      Console.WriteLine("Types...");
      for (int i = 0; i < type.Length; i++)
         Console.WriteLine(" {0}", type[i]);
   }
}

Output

This will produce the following output −

Types...
System.Double
System.Int32
System.Int32
System.Int32
System.String

Example

Let us now see another example to implement the Type.GetTypeArray() method −

using System;
using System.Reflection;
public class Demo {
   public static void Main(){
      Object[] obj = new Object[5];
      obj[0] = 100m;
      obj[1] = 20.98;
      obj[2] = 30.788m;
      obj[3] = 40;
      obj[4] = "jack";
      Type[] type = Type.GetTypeArray(obj);
      Console.WriteLine("Types...");
      for (int i = 0; i < type.Length; i++)
         Console.WriteLine(" {0}", type[i]);
   }
}

Output

This will produce the following output −

Types...
System.Decimal
System.Double
System.Decimal
System.Int32
System.String

Updated on: 11-Nov-2019

15 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements