Consider the following:
static void Main(string[] args)
{
List<object> someList = new List<object>();
someList.Add(1);
someList.Add(2);
someList.Add("apple");
someList.Add(true);
someList.Add(3);
}
The list items have not been defined with a data type and contains a boolean, a string, and an integer. Assuming there are many more list items of varying data types, how do I sum only the integers (such as 1, 2, and 3) from the list of objects using a simple loop or if statement? I'm just beginning in C#, thank you!
After searching, I've tried something like this, but with no success:
if(!someList.Contains(int))
List.Add(int);