I have now updated to a Complex Situation now and i am terribly stuck. Kindly Let me know if you can share some light to it.
I No more have this as List<string>. It is now a List<categories> Which will have the Following properties
public class Categories
{
public string DisplayName { get; set; }
public string ValueCode { get; set; }
public string Count { get; set; }
}
This will have Values like
Category1/SubCategory1
cat1/sc1
5
Category1/SubCategory2
cat1/sc2
4
Category 2/Subcategory1
cat2/sc1
5
Category 2/Subcategory2
cat2/sc2
23
So, i updated my Existing JobCateogry Clas and so on.
public class JobCateogry
{
public string DisplayName { get; set; }
public string ValueCode { get; set; }
public string Count { get; set; }
public List<JobCateogry> SubCategories { get; set; }
}
I tried to Split the string and assign it to the new class in two step first by splitting and then by assiging. But i am sure i am doing it the wrong way, because the moment i split, i loose the count .
var lstCategory = Categories
.Where(i => i.count > 0)
.Select(item => item.valueCode.Split('/')
.Select(k =>(k)).ToList();
List<JobCategories> jobcategories = lstCategory
.Select(item => item.Split(QueryStringConstants.CAT_SEPERATOR.ToCharArray()[0]))
.GroupBy(tokens => tokens[0].Trim(), tokens => tokens[1])
.Select(g => new JobCategories(g.Key, g.DisplayName,g.ToList(),)).ToList();
Can you please help?
(i need to split by Value code and Show the DisplayName and Count)
* Old Question * I have a List that has strings something like this
"Category1/SubType1"
"Category1/SubType2"
"Category1/SubType3"
"Category1/SubType4"
"Category2/SubType1"
"Category2/SubType2"
"Category2/SubType3"
"Category2/SubType4"
i have a class that has two properties.
public string Category { get; set; }
public List<string> SubCategory{ get; set; }
I need to iterate through the list, and pick all the categories and then add subcategories to them.
I had sorted the list and I was able to achieve the traditional way by doing a for loop by taking the first string and comparing with the rest. I was wondering if there is any neater way to do this?