|
-
March 13th, 2012, 01:02 PM
#1
Trying to find date of 2010 for all records in a list (version 4.0)
I'm going thru a list and trying to find only the records that have 2010 as their year and displaying the the record using this code:
var dateSorted =
from e in deserializedRoster
where DateTime.Equals = "2010"
select e;
foreach (var e in dateSorted) Console.WriteLine("Date 2010: {0}", e.ToString());
Console.WriteLine();
The line DateTime.Equals needs work. I don't know how to instruct the code to look only for 2010 in the year. The field is called "date".
-
March 13th, 2012, 02:08 PM
#2
Re: Trying to find date of 2010 for all records in a list (version 4.0)
The big problem is your WHERE clause. If the field is named date, then it needs to be:
Code:
var dateSorted = from e in deserializedRoster
where e.date.Year = "2010"
select e
You have to do your where on the temp variable you assign in your from statement. I'm assuming that the "date" field is a DateTime type, which is why I'm using the Year parameter to check.
HTH
Code:
if (Issue.Resolved)
{
ThreadTools.Click();
MarkThreadResolved();
}
-
March 13th, 2012, 02:33 PM
#3
Re: Trying to find date of 2010 for all records in a list (version 4.0)
Secondly... .Equals is a method, not a property...
If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.
Yes; I have a blog too - http://the-angry-gorilla.com/
-
March 13th, 2012, 02:36 PM
#4
Re: Trying to find date of 2010 for all records in a list (version 4.0)
I changed the code to reflect what you indicated and I'm getting two errors:
"Property or indexer 'System.DateTime.Year' cannot be assigned to -- it is ready only"
And:
"Cannot implicitly convert type 'string' to 'int'
-
March 13th, 2012, 02:44 PM
#5
Re: Trying to find date of 2010 for all records in a list (version 4.0)
He left of a '=' The equality operator is ==, not =. Also, DateTime.Year is an int, so remove the quotes around "2010".
If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.
Yes; I have a blog too - http://the-angry-gorilla.com/
-
March 13th, 2012, 02:53 PM
#6
Re: Trying to find date of 2010 for all records in a list (version 4.0)
Yeah, I'm always forgetting the second = for equality operators.
Code:
if (Issue.Resolved)
{
ThreadTools.Click();
MarkThreadResolved();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|