class orders
{
public string orderNumber { get; set; }
public string id { get; set; }
public List<string> idList { get; set; }
}
I have a list of orders that can be anywhere from 1 to 100. I need to assign each member of the list all of the "id"s of the other members of the list where the "orderNumber" is the same. I want to assign this to the "idList" list of strings. Within the list of orders, there might be multiple sets of orders that have the same "orderNumber".
I've tried to logically think this out but cannot come up with a solution that works.
I tried the following:
List<string> temp = new List<string>();
for (int x = 0; x < orders.Count; x++)
{
if (string.Equals(orders[x].orderNumber, orders[x + 1].orderNumber))
{
temp.Add(orders[x].id);
temp.Add(orders[x + 1].id);
i++;
}
else
{
for(int o = 0; o < i; o++)
{
orders[o].idList= new List<string>();
orders[o].idList= temp;
}
i = 0;
temp.Clear();
}
}
"cannot come up with a solution that works."-- show us solutions that didnt work then. We aren't a code writing service