Following is the data collection of objects in an array, which contains Integer, Float, Boolean, String and Null data,
object data = new object[] {
1,
true,
"b",
"a",
false,
1,
null,
8,
2.3
};
// Convert the object of into array of objects
object[] actualValues = (Object[]) data;
int sumIntegers = 0;
// Traverse the object array to get the each item
foreach(var item in actualValues) {
if (item != null) {
Type tp = item.GetType();
// Get the type and check if Integer then sum the value
// Here you can apply condition according to your requirement with typeof
if (tp.Equals(typeof(int))) {
sumIntegers += (int) item;
}
}
}
// Sum of all Integer Values. In this scenario it will display Sum of Integer Values: 10
Console.WriteLine("Sum of Integer Values: " + sumIntegers);