https://stackoverflow.com/questions/77539127/what-is-the-idiomatic-way-to-populate-a-list-of-lists-in-c

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
using System.Linq;

//https://stackoverflow.com/questions/77539127/what-is-the-idiomatic-way-to-populate-a-list-of-lists-in-c

    public struct Bar
    {
        public float val;

        public Bar(float val) {  this.val = val; }  
    }

    internal class Program
    {
        public static void Main()
        {
            int rows = 3;
            int cols = 4;

			var mat = Enumerable.Range(0, rows)
				.Select(iRow => Enumerable.Range(iRow*cols, cols).Select(iCell => new Bar(iCell)).ToList())
				.ToList();
			
            foreach (var row in mat)
            {
                foreach (var item in row)
                {
                    Console.Write(item.val + " ");
                }
                Console.Write("\n");
            }
        }
    }
;