this may be very fundamental C# question as I only study C# myself there are things that I do not have the logic to start.
I have a class CustomerSite with string Customer {get;set} and string Site {get;set;}
I create a list List<CustomerSite> listCustomerSite= new List<CustomerSite>();
Assume, I have a list with the following data
SAMSUNG CHINA
SAMSUNG AMERICA
SAMSUNG AFRICA
LG CHINA
APPLE AMERICA
APPLE CHINA
I would like to have 1 concatenated string
string Result = "APPLE (AMERICA, CHINA), LG (CHINA), SAMSUNG (AFRICA, AMERICA, CHINA)"
How could I do that?
My idea is to use a dictionary to keep a list of distinct Customers and adding the site to the string but I still have no clue how to deal with sorting (AFRICA --> AMERICA --> CHINA)
Dictionary<string, int> dictCustomer = new Dictionary<string, int>();
foreach (var i in listCustomerSite)
{
if (!dictCustomer.ContainsKey(i.Customer))
{
dictCustomer.Add(i.Customer, 0);
Result = Result + "," + "i.Customer" + "( i.Site) ";
}
else
{
Result.Replace(")", "," + i.Site + ")");
}
}