Hello,
I am need to create a range of year that goes from current year minus
70 to current year minus 16.
I want the recent years first. I am using:
Enumerable.Range(DateTime.UtcNow.AddYears(-16).Year,
DateTime.UtcNow.AddYears(-70).Year)
The problem is that I get 1994 to 3933.
What am I doing wrong?
Thanks,
Miguel
|
|
0
|
|
|
|
Reply
|
shapper
|
1/17/2010 10:58:40 PM |
|
shapper wrote:
> Hello,
>
> I am need to create a range of year that goes from current year minus
> 70 to current year minus 16.
> I want the recent years first. I am using:
>
> Enumerable.Range(DateTime.UtcNow.AddYears(-16).Year,
> DateTime.UtcNow.AddYears(-70).Year)
>
> The problem is that I get 1994 to 3933.
>
> What am I doing wrong?
Did you actually read the documentation for the Enumerable.Range()
method before you tried to use it?
http://msdn.microsoft.com/en-us/library/system.linq.enumerable.range.aspx
IMHO, the documentation makes it very clear what you've done wrong.
But, if after reading it you are still confused, please explain exactly
what about the documentation doesn't make sense to you. One particular
place to start would be to explain why it is you feel each value you are
passing to the method is justified given the documentation for that
parameter of the method.
Pete
|
|
0
|
|
|
|
Reply
|
Peter
|
1/17/2010 11:31:56 PM
|
|
On Jan 17, 11:31=A0pm, Peter Duniho <no.peted.s...@no.nwlink.spam.com>
wrote:
> shapper wrote:
> > Hello,
>
> > I am need to create a range of year that goes from current year minus
> > 70 to current year minus 16.
> > I want the recent years first. I am using:
>
> > Enumerable.Range(DateTime.UtcNow.AddYears(-16).Year,
> > DateTime.UtcNow.AddYears(-70).Year)
>
> > The problem is that I get 1994 to 3933.
>
> > What am I doing wrong?
>
> Did you actually read the documentation for the Enumerable.Range()
> method before you tried to use it?
>
> http://msdn.microsoft.com/en-us/library/system.linq.enumerable.range....
>
> IMHO, the documentation makes it very clear what you've done wrong.
> But, if after reading it you are still confused, please explain exactly
> what about the documentation doesn't make sense to you. =A0One particular
> place to start would be to explain why it is you feel each value you are
> passing to the method is justified given the documentation for that
> parameter of the method.
>
> Pete
Got it ... I have been using Enumeration always starting at 1 so I
ended up with the idea that it was start and end not start and count.
So I was completly convinced that the problem was with my DateTime
approach. Anyway it is working now:
Enumerable.Range(DateTime.UtcNow.AddYears(-70).Year,
55).OrderByDescending(i =3D> i)
Thanks,
Miguel
|
|
0
|
|
|
|
Reply
|
shapper
|
1/18/2010 12:30:24 AM
|
|
shapper wrote:
> Hello,
>
> I am need to create a range of year that goes from current year minus
> 70 to current year minus 16.
> I want the recent years first. I am using:
>
> Enumerable.Range(DateTime.UtcNow.AddYears(-16).Year,
> DateTime.UtcNow.AddYears(-70).Year)
>
> The problem is that I get 1994 to 3933.
You've asked for a range running from (2010 - 16) = 1994 and lasting
(2010 - 70) = 1940 years, until the year (1994 + 1940 - 1) = 3933.
|
|
0
|
|
|
|
Reply
|
Harlan
|
1/18/2010 12:39:08 AM
|
|
shapper wrote:
> Got it ... I have been using Enumeration always starting at 1 so I
> ended up with the idea that it was start and end not start and count.
> So I was completly convinced that the problem was with my DateTime
> approach. Anyway it is working now:
>
> Enumerable.Range(DateTime.UtcNow.AddYears(-70).Year,
> 55).OrderByDescending(i => i)
Of course, the above is a painfully clear example of overuse of LINQ.
Sorting a range of numbers by descending order, when the range is
_already_ sorted is ridiculous overhead. There's nothing the above
achieves that makes it superior to:
int year = DateTime.UtcNow.AddYears(-16),
yearLast = year - 55;
while (year > yearLast)
{
// do something
year--;
}
Even if for some reason you decided you needed the numbers represented
as an IEnumerable<int>, but didn't want them stored in some temporary
storage as you were enumerating them (an obvious contradiction with your
chosen implementation, but let's say that constraint exists just for the
sake of discussion), then something like this would make more sense:
IEnumerable<int> Range(int start, int count)
{
if (count >= 0)
{
return Enumerable.Range(start, count);
}
if (start + count + 1 > start)
{
throw new ArgumentOutOfRangeException("when count is negative,
start + count + 1 cannot be less than Int32.MinValue");
}
while (count < 0)
{
yield return start++;
count++;
}
}
Hope that helps.
Pete
|
|
0
|
|
|
|
Reply
|
Peter
|
1/18/2010 12:54:30 AM
|
|
Peter Duniho wrote:
> [...]
> while (count < 0)
> {
> yield return start++;
>
> count++;
> }
The above should, of course, read:
while (count < 0)
{
yield return start--;
count++;
}
I'm guessing everyone can figure that out though. :)
|
|
0
|
|
|
|
Reply
|
Peter
|
1/18/2010 1:05:25 AM
|
|
|
5 Replies
21947 Views
(page loaded in 0.002 seconds)
Similiar Articles: select query including dates outside of specified range ...... even those with Admit Dates AFTER the Requested Date. What am I doing wrong? ... Subtract 1 Year from Query Date Range ... that anyone can go into and select a date range ... Conditional format on adjacent cells - microsoft.public.excel ...Hi All, what am I doing wrong ... change the range then need to change the 7. -- Regards, OssieMac "Simon" wrote: > Hi All, > what am I doing wrong?? Justifying text across a range of cells Excel 2007? - microsoft ...When I select the range and then click the justify button it justifies the text in the original single cell. What am I doing wrong? Is there some other format ... remove crlf - microsoft.public.excel.programmingWhat am I doing wrong? Dim aCell As Range Sub Remove_CR_LF() For Each aCell In Selection With Selection .Replace What:=Chr(13) & Chr(10 ... Running code when hyperlink clicked - microsoft.public.excel ...What am I doing wrong? Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink) Sheets("Sheet1").Range("B1") = "It Ran" End Sub 2. ICommand. What am I doing wrong? - microsoft.public.dotnet ...- Behind the Badge of a Deputy Sheriff What am I doing wrong? Hello .. I am 20 years old. I am pregnant. Me and my boyfriend split up about 3 weeks after I found out I was ... How can I define date range criteria in SUMIF formula? - microsoft ...What am I doing wrong?? ... criteria for a range of dates (ie a > month). Have tried for eg >=DATE(2010,1,31) and this brings no result... > > What am I doing wrong?? How to Calculate if a Range of Times Falls Between two Date/Time S ...What am I doing wrong? b. How could I expand the formula to include checking for the full time range (18:00 - 18:30)? ... Calculating age at different points ... DocVariable wont work - microsoft.public.word.vba.general ...> What am I doing wrong: 1: I created a macro associated to the CTRL-K keyboard sequence. ... > It was around August last year. I can't recall all the details, but the ... Format Problem - microsoft.public.access.formscodingThe current year If you then convert the 2010 to ... > > What am I doing wrong in both cases? -- Fred Please ... problem is that I can't conditionally format a range ... I Am A 53 Year Old Man. Why Can't I Find A Date? | The Urban DailyWhat am I doing wrong here and why can’t I find a woman who will accept me as I am? ... Look to see if there are any singles cruises that encompass your age range. What am I doing wrong? - Queendom: personality tests, IQ tests ...What am I doing wrong? Will, 20-year-old man: Answer: Dear Will, When I was your age, I was in exactly the same place. Every girl I met became my sister instead of my lover. Had acne for four years, what am I doing wrong?Had acne for four years, what am I doing wrong? ... apparently causes acne, but I've had acne for years now and I need to know what I'm doing wrong. 23 years old and never had a job.... What am I doing wrong ...Best Answer: You can't really expect a high school diploma to get you anywhere. Bringing it to the interview wouldn't make any difference...if we were ... My chickens won't lay eggs. What am I doing wrong? - Yahoo! AnswersAm I doing something wrong? When I was a kid we had a flock of ... they in an enclosed pen, or do they free range ... they are fully grown, around 9 months of age 7/31/2012 7:07:52 AM
|