Как объявить массив чтобы им можно было пользоваться в любом методе? - C#
Формулировка задачи:
string[] lines = File.ReadAllLines("C:/input.txt");
int[,] A = new int[lines.Length, lines[0].Split(' ').Length];
for (int i = 0; i < lines.Length; i++)
{
string[] temp = lines[i].Split(' ');
for (int j = 0; j < temp.Length; j++)
A[i, j] = Int32.Parse(temp[j]);
}Решение задачи: «Как объявить массив чтобы им можно было пользоваться в любом методе?»
textual
Листинг программы
using System;
namespace Application
{
class MainClass
{
static int [] A = new int[10];
static void Filling()
{
Random gen = new Random ();
for (int i = 0; i < A.Length; i++)
A[i] = gen.Next (1, 10);
}
static void Show ()
{
foreach (int item in A)
{
Console.Write (item + " ");
}
Console.WriteLine ();
}
public static void Main (string[] args)
{
Filling ();
Show ();
}
}
}