Как проверить, есть ли значение, которое пользователь вводит с консоли.
У меня есть пять значений перечисления:
enum Fruits
{
apple = 1,
orange,
banana,
chery,
kiwi
}
И создал массив этих значений:
Array arrayFruits = Enum.GetValues(typeof(Fruits));
Следующий код:
Console.WriteLine("Enter plant");
string plantNotLow = Console.ReadLine();
string plant = plantNotLow.ToLower();
object element = Enum.Parse(typeof(Fruits), plant);
Fruits fruit = (Fruits)element;
Array arrayFruits = Enum.GetValues(typeof(Fruits));
for (int i = 0; i < arrayFruits.Length; i++)
{
if(arrayFruits.GetValue(i) == element)
{
}
}
Например, пользователь вводит "яблоко", как войти в блок if?