I am trying to check the int values in an array and based on that do some calculation but the code is not working below is the code:
string EventIds = getVoucher.EventIDs;
int[] array = EventIds.Split(',')
.Select(x => int.Parse(x, CultureInfo.InvariantCulture))
.ToArray();
if(array.ToString().Any(s => booking.EventID.ToString().Contains(s)))
{do something; } else { do something;}
array.ToStringreturns the string"System.Int32[]". UsingAnywith a string checks the predicate for each character in the string.Assuming that
booking.EventIDis anintsuch as1234,booking.EventID.ToString()returns the string"1234".So your code checks if
"1234"contains any character in"System.Int32[]"(here:true, because"1234"contains the'3'of"System.Int32[]").You don’t say what the desired result is, but I guess you’re looking for something like this:
or