using System.Collections.Generic;
public static class TypeChecker
public static int CountInstanceOfType(object[] objects, Type targetType)
if (objects == null || targetType == null)
foreach (var obj in objects)
if (obj != null && targetType.IsInstanceOfType(obj))
public static void Main()
object[] objects = new object[] { 1, "hello", 3.14, new List<int>(), "world" };
Type targetType = typeof(string);
int count = TypeChecker.CountInstanceOfType(objects, targetType);
Console.WriteLine($"Count of Instance Of Type [{targetType.Name}]: {count}");
objects = new object[] { 1, "hello", 3.14, new List<int>(), "world" };
targetType = typeof(int);
count = TypeChecker.CountInstanceOfType(objects, targetType);
Console.WriteLine($"Count of Instance Of Type [{targetType.Name}]: {count}");
objects = new object[] { 1, "hello",2.1, 2, 3.14, 5.6 };
targetType = typeof(double);
count = TypeChecker.CountInstanceOfType(objects, targetType);
Console.WriteLine($"Count of Instance Of Type [{targetType.Name}]: {count}");