Concatenate 12+ List of equal length in C#

unhandled
csharp

#1

Hi there,

This is my 2nd incursion in C# code, and I need to improve my scripting and optimisation of my code.

The idea behind this C# Code that it must concatenate 12 lists of equal lengths, & 1 text input, in this order (list 1 --> text input --> list 2 … and so it goes).

So I need:

  1. Check the 12 list of values to see if they’re of equal length.
  2. In case of any list that doesn’t comply with the first condition, the component must tell me which list have the error.
  3. If every thing is ok, then the script will concatenate the lists in the order that I have mentioned before.
     //List length paraameter
    int lLength = nData00.Count;

    //Result List
    List<string> resultList = new List<string>();

    //Length tester
    if(nData00.Count != nData01.Count){
      System.Console.WriteLine("nData00 # nData01");
    }

    if(nData01.Count != nData02.Count){
      System.Console.WriteLine("nData01 # nData02");
    }

    if(nData02.Count != nData03.Count){
      System.Console.WriteLine("nData02 # nData03");
    }

    if(nData03.Count != nData04.Count){
      System.Console.WriteLine("nData03 # nData04");
    }

    if(nData04.Count != nData05.Count){
      System.Console.WriteLine("nData04 # nData05");
    }

    if(nData05.Count != nData06.Count){
      System.Console.WriteLine("nData05 # nData06");
    }

    if(nData06.Count != nData07.Count){
      System.Console.WriteLine("nData06 # nData07");
    }

    if(nData07.Count != nData08.Count){
      System.Console.WriteLine("nData07 # nData08");
    }

    if(nData08.Count != nData08.Count){
      System.Console.WriteLine("nData08 # nData09");
    }

    if(nData09.Count != nData10.Count){
      System.Console.WriteLine("nData09 # nData10");
    }

    if(nData10.Count != nData11.Count){
      System.Console.WriteLine("nData10 # nData11");
    }

    if(nData11.Count != nData12.Count){
      System.Console.WriteLine("nData11 # nData12");
    }

    //Concatonator Loop
    for(int i = 0; i < lLength; i++){
      string itemTemp01 = "Pgon{2} ";
      string itemTemp02 = nData00[i] + conSymbol + nData01[i] + conSymbol + nData02[i] + conSymbol + nData03[i] + conSymbol;
      string itemTemp03 = nData04[i] + conSymbol + nData05[i] + conSymbol + nData06[i] + conSymbol;
      string itemTemp04 = nData07[i] + conSymbol + nData08[i] + conSymbol + nData09[i] + conSymbol;
      string itemTemp05 = nData10[i] + conSymbol + nData11[i] + conSymbol + nData12[i];

      resultList.Add(itemTemp01 + itemTemp02 + itemTemp03 + itemTemp04 + itemTemp05);

      //resultList = nData01[i].Concat
    }

    A = resultList;

Thank you in advance.


(David Rutten) #2

Quick tip, when putting multi-line code into a discourse post, put three ticks in front and behind it:

```
code here
```

I’d put all the lists into a single array, so you can perform the comparisons in a loop.
Same with your concatenation, find a way to loop over those 12 collections.

You can use string.Join() with your conSymbol to combine a collection of text elements.


#3

@DavidRutten

1st, thank you for the tip

2nd, you answer just made me think in another way to do it using your idea.

And thank you again