-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample011_Array
More file actions
51 lines (43 loc) · 1.11 KB
/
Example011_Array
File metadata and controls
51 lines (43 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
void FillArray(int[] collection)
{
int length = collection.Length; //получаем длину списка
int index = 0; //по умолчанию позиция индикса начинается с 0
while(index < length)
{
collection[index] = new Random().Next(1, 10);
index++;
}
}
//Создаем метод, который будет печатать массив
void PrintArray(int[] col)
{
int count = col.Length;
int position = 0;
while(position < count)
{
System.Console.WriteLine(col[position]);
position++;
}
}
int IndexOf(int[] collection, int find)
{
int count = collection.Length;
int index = 0;
int position = -1; //переменная для хранения значения
while (index < count)
{
if (collection[index] == find)
{
position = index;
break;
}
index++;
}
return position;
}
int[] array = new int[10];
FillArray(array);
PrintArray(array);
System.Console.WriteLine();
int pos = IndexOf(array, 444);
System.Console.WriteLine(pos);