Click here to Skip to main content
15,915,757 members
Please Sign up or sign in to vote.
1.60/5 (2 votes)
See more:
Hey all,

I would like to select a value from a record that is one previous from the current record based on the DateTime value (specifically: year) that is being input and one that is already in there (unless first row). My id's skip because of deletes (I suppose a fix-it method for that would work too).

Anyone want to help me with the query? (Note: I have re-ordered ID's before, but I forget which language that was in when I did it, I can't seem to find a reference on that, and doing that often seems like it would be a waste of resources).

Thanks,

Ruben
Posted

1 solution

I hope this help you
C#
//list object
var lstValue = new List<int>();
//insert 0 -> 19
for (var i = 0; i < 20; i++)
    lstValue.Add(i);
//set up currentValue
var crValue = 3;
//sort list by
lstValue = lstValue.OrderByDescending(s => s).ToList();
//get index of current value
var index = lstValue.IndexOf(crValue);
Console.WriteLine(index);
//get value previous
if (index > 0)
{
    var prvValue = lstValue.Skip(index - 1).First();
    Console.WriteLine(prvValue);
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900