Good evening! I made an array of the structure in a separate class, but, unfortunately, the loop fills the array only in the first iteration, as far as I was able to figure out how to solve this. Checked it with the MessageBox output (Convert.ToString (i)); but it was output only 1 time and that's it. There were ideas that, unlike Delphi, in C # it is forbidden to display pop-up windows too often, but having tried to derive MessageBox (Convert.ToString (B [80] .X)) with an array of 100 elements, it would output 0 he did not get it.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace Sorting { class MainArray { protected struct StructArray { internal short X,Value; internal byte R, G, B; } protected Random Random; protected StructArray[] B; //Конструктор класса public MainArray(ushort Count) { B = new StructArray[Count]; StructArray myElem = new StructArray(); for (int i = 0; i < Count; i++) { myElem.X = Convert.ToInt16(i*10); myElem.Value = Convert.ToInt16(Random.Next(1025)); myElem.R = Convert.ToByte(Random.Next(256)); myElem.G = Convert.ToByte(Random.Next(256)); myElem.B = Convert.ToByte(Random.Next(256)); B[i] = myElem; } System.Windows.Forms.MessageBox.Show(Convert.ToString(B[80].X)); } //Конструктор для потомков public MainArray() { // TODO: Complete member initialization } } }