Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
class Program
   {
       static void Main(string[] args)
       {
           string[] set1 = { "AA0", "BC1", "XYZ", "000" };
           string[] set2 = { "AZ0", "BXY", "HIJ" };
           string[] set3 = { "A12", "BHO", "LMN" };

           ArrayList al = new ArrayList();
           al.Add(set1);
           al.Add(set2);
           al.Add(set3);



           List<List<string>> obj = new List<List<string>>();

           for (int i = 0; i < al.Count; i++)
           {

               for (int j = 0; j < 3; j++)
               {
                   List<string> allset = new List<string>();
                   var a = al.Cast<string[]>().ToList();
                   allset.AddRange(a[j]);
                   obj.Add(allset);
               }
           }

           //var itm = from d in obj select d[k].ToArray();
           //foreach (var item in itm)
           //{
           //    Console.WriteLine(item);
           //}
           for (int l = 0; l < obj.Count; l++)
           {
               for (int k = 0; k < 3; k++)
               {
                   //Console.WriteLine(obj[k]);
               }
           }
           int loopnumber = 1;

           ArrayList l2 = new ArrayList();
           for (int i = 0; i < obj.Count; i++)
           {



               for (int m = 0; m < obj[i].Count; m++)
               {
                   string str = "";
                   //condition_1: swap 3rd column of matrix
                   if (loopnumber == 1)
                   {
                       str += obj[i][0].ToString() + obj[i][1] + obj[m][2];

                   }
                   //condition_1: swap 3rd column of matrix
                   else if (loopnumber == 2)
                   {
                       //if (m == 0)
                       //{
                       //    i = 0;
                       //}

                       str += obj[i][0].ToString() + obj[m][1] + obj[i][2];

                   }
                   //condition_1: swap 3rd column of matrix
                   else if (loopnumber == 3)
                   {
                       //if (m == 0)
                       //{ i = 0; }

                       str += obj[m][0].ToString() + obj[i][1] + obj[i][2];
                   }
                   //if (l2.Contains(str) == false)
                   //{
                   l2.Add(str);
                   //}
               }
               //str += set1[i] + set1[i + 1] + set1[i + 2];
               //}
               if (i == 8)
               {
                   loopnumber++;
                   i = 0;
                   if (loopnumber > 3)
                   {
                       break;
                   }
               }
           }

i am using the above method but it is not working for dynamic columns .
and i searched for solution or technique but all i got is for row wise .but my requirement is column wise .please help me with this .
Posted
Updated 20-Jan-16 1:28am
v2
Comments
dan!sh 20-Jan-16 2:09am    
So you want to merge 3 arrays? Is this correct output you are looking for: AA0", "AZ0","A12","BC1", "BXY", "BHO","XYZ","HIJ","LMN", "000"
RAJU-11052090 20-Jan-16 2:52am    
hi thanks for replying sir ,
sorry for late reply
Q:
C1 C2 C3 C4
R1 { "AA0", "BC1", "XYZ", "000" };
R2 { "AZ0", "BXY", "HIJ" };
R3 { "A12", "BHO", "LMN" };
---- ----- ---- ----
3 * 3 * 3 * 1 = 27

Ans is :

AA0 BC1 XYZ 000
AA0 BC1 HIJ 000
AA0 BC1 LMN 000

AA0 BXY XYZ 000
AA0 BXY HIJ 000
AA0 BXY LMN 000

AA0 BHO XYZ 000
AA0 BHO HIJ 000
AA0 BHO LMN 000

AZ0 BXY XYZ 000
AZ0 BXY HIJ 000
AZ0 BXY LMN 000

AZ0 BC1 XYZ 000
AZ0 BC1 HIJ 000
AZ0 BC1 LMN 000

AZ0 BH0 LMN 000
AZ0 BHO HIJ 000
AZ0 BHO LMN 000

A12 BHO XYZ 000
A12 BHO HIJ 000
A12 BHO LMN 000


A12 BC1 XYZ 000
A12 BC1 HIJ 000
A12 BC1 LMN 000

A12 BXY LMN 000
A12 BXY HIJ 000
A12 BXY LMN 000

LIKE THIS IT SHOULD GIVE 27


amagitech 20-Jan-16 2:22am    
what is your aim I don't understand.Can you explain it easyly
RAJU-11052090 20-Jan-16 4:22am    
hi thanks replying ,

i have explained the complete requirement in below one
RAJU-11052090 20-Jan-16 2:51am    
Hi thanks for replying ,

Q:
C1 C2 C3 C4
R1 { "AA0", "BC1", "XYZ", "000" };
R2 { "AZ0", "BXY", "HIJ" };
R3 { "A12", "BHO", "LMN" };
---- ----- ---- ----
3 * 3 * 3 * 1 = 27


Ans is :

AA0 BC1 XYZ 000
AA0 BC1 HIJ 000
AA0 BC1 LMN 000

AA0 BXY XYZ 000
AA0 BXY HIJ 000
AA0 BXY LMN 000

AA0 BHO XYZ 000
AA0 BHO HIJ 000
AA0 BHO LMN 000

AZ0 BXY XYZ 000
AZ0 BXY HIJ 000
AZ0 BXY LMN 000

AZ0 BC1 XYZ 000
AZ0 BC1 HIJ 000
AZ0 BC1 LMN 000

AZ0 BH0 LMN 000
AZ0 BHO HIJ 000
AZ0 BHO LMN 000

A12 BHO XYZ 000
A12 BHO HIJ 000
A12 BHO LMN 000


A12 BC1 XYZ 000
A12 BC1 HIJ 000
A12 BC1 LMN 000

A12 BXY LMN 000
A12 BXY HIJ 000
A12 BXY LMN 000

LIKE THIS IT SHOULD GIVE 27

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900