Click here to Skip to main content
16,019,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
What i have :

C#
public class Prozess
       {
           public string one { get; set; }
           public string two { get; set; }
           public string three { get; set; }
           public string four { get; set; }
           public string five { get; set; }
           public string six { get; set; }
           public string seven { get; set; }
       }

List<Prozess> Persons = new List<Prozess>();


what i try to do is to add items to the list in a for loop.
what i already have is

C#
Prozess Person = new Prozess();
        Person.one = "78";
        Person.two = "50";
        Person.three = "5";
        Person.four = "15";
        Person.five = "10";
        Person.six = "5";
        Person.seven= "15";
        Persons.Add(Person);
        Prozess Person1 = new Prozess();
        Person1.one = "88";
        Person1.two = "35";
        Person1.three = "34";
        Person1.four = "5";
        Person1.five = "66";
        Person1.six = "5";
        Person1.seven = "15";
        Persons.Add(Person1);


problem is that i want to convert this into a for loop .these number sets come from an array i want to loop the array so it will write into the list.
Posted

1 solution

Assuming you have an array such as
C#
string[][] myData = new string[][] {new string[] {"78", "50", " 5", "15", "10", " 5", "15"},
                                    new string[] {"88", "35", "34", " 5", "66", " 5", "15"}};

then:
C#
foreach (string[] row in myData)
    {
    Prozess p = new Prozess();
    p.one = row[0];
    p.two = row[1];
    p.three = row[2];
    p.four = row[3];
    p.five = row[4];
    p.six = row[5];
    p.seven = row[6];
    Persons.Add(p);
    }
 
Share this answer
 
Comments
Amd_eagle 25-Mar-11 5:35am    
Thax for the reply much appriciated.i have not tried ur solution yet but before that i found another way to solve the issue and its seem to be working. the solution is a follows.

List<Prozess> Persons = new List<Prozess>();
forloop{
Persons.Add(new Prozess()
{ one=arr[0],
two=arr[1],
three=arr[2],
four=arr[3],
five=arr[4],
six=arr[5],
seven=arr[6]
});
}

Thax any way i will try your method too. Thank you

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