Click here to Skip to main content
15,906,285 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear All,
hii iam new in c# an i want to know How can i iterate on List<object> to give me specific output data
ex
C#
List<object> sParameterValues ;
where:
sParameterValues [0]=[1,2,3];
sParameterValues [1]=["test","new","11"];
sParameterValues [2]=["value","pla"];
                 .
                 .
sParameterValues [n]=["test3","pla","val2"];

the out put that i need

1 ^"test" ^"value" ^......n ^ "test3"  ,  2 ^"new" ^"pla" ^......n ^ "pla" ,3^"11"^" "^......n ^"val2"


thanks
Posted
Updated 28-Apr-15 14:16pm
v3
Comments
Sergey Alexandrovich Kryukov 28-Apr-15 20:24pm    
Helping you would be much less effective that just reading on the topic. If you have problems reading original MSDN documentation on such a simple topic, helping you would be a huge waste of time, because nothing can suggest that it could be any better.
—SA

You certainly need to learn iterations by yourself, this is the topic you cannot afford being ignorant about:
https://msdn.microsoft.com/en-us/library/ch45axte.aspx[^],
https://msdn.microsoft.com/en-us/library/ttw7t8t6.aspx[^].

Note that foreach loop is based on the objects implementing System.IEnumerable interface, which is of course implemented by all arrays, lists, and other collections:
https://msdn.microsoft.com/en-us/library/system.collections.ienumerable%28v=vs.110%29.aspx[^].

But first of all, examine the problem thoroughly; you may not need to iterate by yourself at all, because you can use available methods which just take the method argument of the delegate type used to be called on each iteration. Please see:
https://msdn.microsoft.com/en-us/library/bb548541(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/bb337697(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/bb534972(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/bb291976(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/bb535050(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/bb340482(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/bb549039(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/bb358775(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/bb549138(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/bb301849(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/bb548915(v=vs.110).aspx[^].

And so on. Whoever has eyes, let them read.

—SA
 
Share this answer
 
v2
Comments
Maciej Los 29-Apr-15 4:00am    
A5!
Sergey Alexandrovich Kryukov 29-Apr-15 9:00am    
Thank you, Maciej.
—SA
Try something like this


C#
List<object> sParameterValues = new List<object>(4);

 sParameterValues.Add( new int[] { 1, 2, 3 }) ;
 sParameterValues.Add(  new string[] { "test", "new", "11" });
sParameterValues.Add(  new string[] { "value", "pla" });
sParameterValues.Add(  new string[] { "test3", "pla", "val2" });

 var intArray = sParameterValues[0] as int[];
 for (int i = 0; i < intArray.Length; i++)
 {
     string content = intArray[i] + " -> ";
     for (int j = 1; j < sParameterValues.Count; j++)
     {
         string[] temp = sParameterValues[j] as string[];
         if (temp.Length > i)
             content += temp[i] + "  ";
     }
     System.Console.WriteLine(content);
 }

 System.Console.ReadLine();
 
Share this answer
 

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