Good day, help figure out how to perform a loop when filling an array. Here is a class with variables:
internal class Transhipment { public float Weight { get; set; } public float WeightThin { get; set; } public float WeightThick { get; set; } public float KalN { get; set; } public float KalV { get; set; } public float ResourceShaft { get; set; } public float[] FloatReserv { get; set; } public int[] IntReserv { get; set; } } Next, I fill in the data from the file and put everything in the List:
var transhipment = new Transhipment() { Weight = read.ReadSingle(), WeightThin = read.ReadSingle(), WeightThick = read.ReadSingle(), KalN = read.ReadSingle(), KalV = read.ReadSingle(), ResourceShaft = read.ReadSingle(), FloatReserv = new[] {read.ReadSingle()}, IntReserv = new[] {read.ReadInt32()} }; result.Add(transhipment); But I need to execute FloatReserv and IntReserv in a loop, if I write inside for I get an error, if I get out of the brackets and write:
transhipment.FloatReserv[1] = read.ReadSingle(); I get the Null exception. Help to understand please. thank
List<int>andList<float>. But such a recordIntReserv = new[] {read.ReadInt32()}creates an array of one element in size, and therefore an error occurs when trying to do this:transhipment.FloatReserv[1] = read.ReadSingle();. And in addition: whenever you start creating a new array, immediately remember that you are writing in C # and it has typed collections, for example List <T>. - BulsonSetFloatReserv(IEnumerable<float> data)methodsSetFloatReserv(IEnumerable<float> data)in the class, and for the second property, similar to fill in with data - BulsonFloatReserv = new[] {read.ReadSingle(), read.ReadSingle(), read.ReadSingle() }? - VladD