- Home /
Check if Item is in array list C Sharp
Is it possible to have a voice input of say various food items, and the somehow check if whatever was said was on the "Food Items" array list to return either a true or false boolean and then execute my audio response based on the true or false state of the boolean?
Comment
Answer by Kishotta · Jul 16, 2017 at 04:38 PM
You can use:
bool found = Array.Contains (myArray, myItem);
if (found) {
// do stuff
else {
// do other stuff
}
also:
string[] foods = new [] {"apple", "pear", "mango", "grapes"};
if (foods.Any(f => f == "apple")) {
//if it found any of "apple" then
//do stuff
}
or:
string[] foods = new [] {"apple", "pear", "mango", "grapes"};
if (foods.Contains("apple")) {
//if foods contains apple then
//do stuff
}
Ah thanks @ShadyProductions I think our VR inputs are being read into Unity as strings so this could very well work. :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Using a Parameterized arraylist (C#)??? 1 Answer
Distribute terrain in zones 3 Answers
Add to Array 1 Answer
How do I print each element of a string array separately to a UI text box 2 Answers