Basic c# question. In the sample bellow But the 'is' doesn't like the type variable. Any ideas there should be a simple answer.
List<object> list = new List<object>();
list.Add("one");
list.Add(2);
list.Add('3');
Type desiredType = typeof(System.Int32);
if (list.Any(w => w is desiredType))
{
//do something
}
Try this:
List<object> list = new List<object>();
list.Add("one");
list.Add(2);
list.Add('3');
Type desiredType = typeof(System.Int32);
if (list.Any(w => w.GetType().IsAssignableFrom(desiredType)))
{
//do something
}
Anyway: are you sure you want to create a list of objects?
w.GetType() == desiredType
.
Why are you abusing generics like that?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With