hi i am trying to find list.contains from my int array basically i am matching list items from my int array
int[] questionName =
{
19294,
19300,
20575,
20826,
20827
};
var ans = (from answer in db.tblAnswers
where answer.tblQuestion.bIsRequired == true
&& questionName.Contains(Convert.ToInt32(answer.nQuestionID))
&& (answer.strAnswer!=" " || answer.strAnswer.Trim()==string.Empty)
&& answer.nQuestionnnaireId==Convert.ToInt32(Session["FormId"].ToString())
select answer).ToList();
List<int> list = new List<int>();
foreach (var i in ans) list.Add(i.nID);
if (list.Contains(Convert.ToInt32(questionName)))
{
PopulateSurvey();
}
but when i run the page i got run time error that
Additional information: Unable to cast object of type 'System.Int32[]' to type 'System.IConvertible'.
I want to match id's from my linq query in my int array. If there is a way please let me know.
int[]to anint. Perhaps you want to convert every single item . But why they are already Integers?nQuestionIdin the database?questionNameis an array, you can't convert an array to an integer. It's not clear what you're trying to check withlist.Contains(Convert.ToInt32(questionName))