Count for datetime object
I'm trying to iterate over DateTime properties on objects in a List collection...
Ex. a tree view that lists the a Name with all its Courses underneath works fine:
// Sorting on name with the courses beneath开发者_运维问答 it:
// *list* is a List<ClsStandholder>;
private void ShowNameWithCourses()
{
treeViewList.Nodes.Clear();
for (int i=0; i < list.Count; i++) {
treeViewList.Nodes.Add(list[i].name);
for (int j=0; j < list[i].courses.Count; j++) {
treeViewList.Nodes[i].Nodes.Add(list[i].courses[j]);
}
treeviewList.ExpandAll();
}
}
That works perfect... where I am having trouble is trying to sort on date and iterate through a count of the dates.
for (int j=0; j < list[i].SubscriptionDate. // how do i put some sort of count for this?
There seems to be no property to loop over all the dates entered.
You need to have a collection of dates in order to be able to use Count
. You are saying that the list is indeed a List<ClsStandholder>
and inside you have courses which is a collection but SubscriptionDate
is a single DateTime
property. How about declaring it as a collection (the same way you've done it for the courses
collection):
public IList<DateTime> SubscriptionDates { get; set; }
The two approaches look like quite different problems. It could be that all clsStandholder
s within list
have the same SubscriptionDate
.
I would recommend making a...
Dictionary<DateTime,List<ClsStandholder>>;
..then iterating through each item in list and adding it to the corresponding list within the dictionary. Then you can iterate through the dates...
The issue Tonz, is that your list
variable is the collection, and the SubscriptionDate
is a single property value on each item in the list. Since the property exists once for each item, there is no Count
.
You could loop through the items, and build a collection of the SubscriptionDates
and iterate over them...
精彩评论