简体   繁体   中英

Convert 3 list of integers into a 2D array in c#

So,I have three separate lists of integers and I want to convert them in a 2D array. I have tried to concat the 3 lists but it becomes a single array not 2D. I want to take the 1st element of each list and form a 2D array.

var startIndex= new List<int>(){ 0, 0, 0, 0 };
var endIndex=   new List<int>(){ 0, 1, 2, 3};
var subs=  new List<int>(){ 0, 1, 1, 0 };
var queries = startIndex.Concat(endIndex).Concat(subs).ToArray(); //this doesn't work

I want something like this-

var queries = [[0,0,0],[0,1,1],[0,2,1],[0,3,0]] //taking first element from each list and so on

I didn't find an eaasy way in c#, any help would be appreciated?

I have started to convert the lists to arrays-

    var startArr = startIndex.ToArray();
    var endArr = endIndex.ToArray();
    var subArr = subs.ToArray();

This will be all you need

        var startIndex = new List<int>() {0, 0, 0, 0};
        var endIndex = new List<int>() {0, 1, 2, 3};
        var subs = new List<int>() {0, 1, 1, 0};
        int maxIndex = startIndex.Count;

        List<List<int>> newList = new List<List<int>>();
        for (int i = 0; i < maxIndex; i++)
        {
            newList.Add(new List<int>() {startIndex[i], endIndex[i], subs[i]});
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM