Jump to content
Tuts 4 You

[C#] How to convert 1D List to 2D List


Perplex

Recommended Posts

The correct approach convert 1D List to 2D List (Randomly)? Please look at the my approach is correct ?

            List<Tuple<object, object, object>> OneDimensionalLists = new List<Tuple<object, object, object>>();
            List<List<Tuple<object, object, object>>> TwoDimensionalLists = new List<List<Tuple<object, object, object>>>();

            int i1 = 0;
            for (int i = 0; i < OneDimensionalLists.Count; i++)
            {
                TwoDimensionalLists.Add(new List<Tuple<object, object, object>>());
                var random = new Random(seed);
                int next = random.Next(10, 30);
                for (int j = 0; j < next; j++)
                {
                    if (OneDimensionalLists.Count == i1)
                        goto go;

                    TwoDimensionalLists[i].Add(OneDimensionalLists[i1++]);
                }
            }
            go:

 

Edited by Perplex
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...