3
int[] trisFront = { 0, 3, 2,  2, 1, 0};
int[] trisRight = { 1, 2, 6,  6, 5, 1 };
int[] trisBack = { 5, 6, 7,  7, 4, 5 };
int[] trisLeft = { 4, 7, 3,  3, 0, 4 };
int[] trisUp = { 3, 7, 6,  6, 2, 3 };
int[] trisBottom = { 4, 0, 1,  1, 5, 4 };

List<int> tris = new List<int>();

tris.Add(trisFront);
tris.Add(trisBack);
tris.Add(trisRight);
tris.Add(trisLeft);
tris.Add(trisUp);
tris.Add(trisBottom);

I want all of trisBottom, Up... to be in tris list, how can I do that?

2
  • Your question is unclear.. What is tris? What is the output you want? Commented Oct 2, 2016 at 8:11
  • public List<int> tris = new List<int>(); Commented Oct 2, 2016 at 8:15

4 Answers 4

5

When using the Add method you are adding 1 item of type T to a collection. Which in your current usage would mean that tris should be a List<int[]> because you are adding an item of type int[].

What you should do is to use the AddRange method instead of Add - that will add all the items from the collections to the end of your tris list:

tris.AddRange(trisFront);
tris.AddRange(trisBack);
tris.AddRange(trisRight);
tris.AddRange(trisLeft);
tris.AddRange(trisUp);
tris.AddRange(trisBottom);
Sign up to request clarification or add additional context in comments.

Comments

1

It sounds like you want List.AddRange:

tris.AddRange(trisFront);

Comments

0

When tris is a GenericList you can just use:

tris.AddRange(trisFront);

In case it's a different DataType let me know.

Comments

-1
    public List<int> tris = new List<int>();

    int[] trisFront = { 0, 3, 2,  2, 1, 0};
    int[] trisRight = { 1, 2, 6,  6, 5, 1 };
    int[] trisBack = { 5, 6, 7,  7, 4, 5 };
    int[] trisLeft = { 4, 7, 3,  3, 0, 4 };
    int[] trisUp = { 3, 7, 6,  6, 2, 3 };
    int[] trisBottom = { 4, 0, 1,  1, 5, 4 };

    tris.AddRange(trisFront);
    tris.AddRange(trisBack);
    tris.AddRange(trisRight);
    tris.AddRange(trisLeft);
    tris.AddRange(trisUp);
    tris.AddRange(trisBottom);

Works perfectly

1 Comment

The correct thing to do, in the case that one of the answers helped you solve your problem is to accept that answer (instead of posting a new answer with the solution)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.