Массив. Последовательная генерация чисел - C#
Формулировка задачи:
Помогите пожалуйста как создать на C# массив в котором будут генерироваться числа от 1 до 100 и программа будет проверять при вводе есть ли число в этом массиве ?
Решение задачи: «Массив. Последовательная генерация чисел»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication36
{
class Program
{
static int n = 100;
static int[] mass = new int[n];
delegate void method();
static void Main(string[] args)
{
string[] items = { "Проверить число ", "Выход" };
method[] methods = new method[] { Method1, Exit };
ConsoleMenu menu = new ConsoleMenu(items);
int menuResult;
Random rnd = new Random();
for (int i = 0; i < n; i++)
{
mass[i] = rnd.Next(0, 100);
}
do
{
menuResult = menu.PrintMenu();
methods[menuResult]();
Console.WriteLine("Для продолжения нажмите любую клавишу");
Console.ReadKey();
} while (menuResult != items.Length - 1);
}
public static void Method1()
{
Console.WriteLine("Введите целое число");
int b = int.Parse(Console.ReadLine());
int priz = -1;
for (int i = 0; i < n; i++)
{
if (b == mass[i])
{
Console.WriteLine("Число совпало");
priz = 0;
break;
};
}
if (priz == -1)Console.WriteLine("Число не совпало");
}
static void Exit()
{
Console.WriteLine("Приложение заканчивает работу!");
}
}
class ConsoleMenu
{
string[] menuItems;
int counter = 0;
public ConsoleMenu(string[] menuItems)
{
this.menuItems = menuItems;
}
public int PrintMenu()
{
ConsoleKeyInfo key;
do
{
Console.Clear();
for (int i = 0; i < menuItems.Length; i++)
{
if (counter == i)
{
Console.BackgroundColor = ConsoleColor.Cyan;
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine(menuItems[i]);
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.White;
}
else
Console.WriteLine(menuItems[i]);
}
key = Console.ReadKey();
if (key.Key == ConsoleKey.UpArrow)
{
counter--;
if (counter == -1) counter = menuItems.Length - 1;
}
if (key.Key == ConsoleKey.DownArrow)
{
counter++;
if (counter == menuItems.Length) counter = 0;
}
}
while (key.Key != ConsoleKey.Enter);
return counter;
}
}
}