Click here to Skip to main content
15,902,938 members
Home / Discussions / C#
   

C#

 
GeneralRe: Need help on how to loop through the following code to find the nearest number above in comparison to another Pin
OriginalGriff11-Mar-10 3:57
mveOriginalGriff11-Mar-10 3:57 
GeneralRe: Need help on how to loop through the following code to find the nearest number above in comparison to another Pin
Richard MacCutchan11-Mar-10 2:33
mveRichard MacCutchan11-Mar-10 2:33 
GeneralRe: Need help on how to loop through the following code to find the nearest number above in comparison to another Pin
suprsnipes11-Mar-10 2:58
suprsnipes11-Mar-10 2:58 
GeneralRe: Need help on how to loop through the following code to find the nearest number above in comparison to another Pin
Keith Barrow11-Mar-10 3:15
professionalKeith Barrow11-Mar-10 3:15 
GeneralRe: Need help on how to loop through the following code to find the nearest number above in comparison to another Pin
Richard MacCutchan11-Mar-10 4:37
mveRichard MacCutchan11-Mar-10 4:37 
GeneralRe: Need help on how to loop through the following code to find the nearest number above in comparison to another Pin
suprsnipes11-Mar-10 5:13
suprsnipes11-Mar-10 5:13 
GeneralRe: Need help on how to loop through the following code to find the nearest number above in comparison to another Pin
Richard MacCutchan11-Mar-10 6:33
mveRichard MacCutchan11-Mar-10 6:33 
GeneralRe: Need help on how to loop through the following code to find the nearest number above in comparison to another Pin
DaveyM6911-Mar-10 8:26
professionalDaveyM6911-Mar-10 8:26 
You could cheat a little and use a list and it's sort method to help. Create the base list, add your value, sort it, get the index of your value and increment to get the next number up. Not very mathmatical or elegant (and probably inefficient) but it works.
C#
class Program
{
    static void Main(string[] args)
    {
        List<string> inputFromFile = new List<string>(3) {
                "4843", "4811", "4792" };
        int value = (int)4820f;
        List<int> list = inputFromFile.ConvertAll(
            new Converter<string, int>(StringToInt));
        list.Add(value);
        list.Sort();
        int index = list.IndexOf(value);
        if (index < (list.Count - 1))
            Console.WriteLine(list[index + 1]);
        else
            Console.WriteLine(value);
        Console.ReadKey();
    }

    private static int StringToInt(string text)
    {
        int result;
        int.TryParse(text, out result);
        return result;
    }
}
Dave

Binging is like googling, it just feels dirtier. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)

QuestionWeb Service authentification server site Pin
olibara10-Mar-10 23:17
olibara10-Mar-10 23:17 
QuestionProblem with list with generic filter predicate. Pin
ddecoy10-Mar-10 22:47
ddecoy10-Mar-10 22:47 
AnswerRe: Problem with list with generic filter predicate. Pin
Keith Barrow10-Mar-10 23:31
professionalKeith Barrow10-Mar-10 23:31 
GeneralRe: Problem with list with generic filter predicate. Pin
ddecoy10-Mar-10 23:52
ddecoy10-Mar-10 23:52 
GeneralSOLVED Pin
ddecoy11-Mar-10 0:03
ddecoy11-Mar-10 0:03 
QuestionFast execution Pin
sanforjackass10-Mar-10 22:31
sanforjackass10-Mar-10 22:31 
AnswerRe: Fast execution Pin
Saksida Bojan10-Mar-10 22:40
Saksida Bojan10-Mar-10 22:40 
GeneralRe: Fast execution Pin
sanforjackass10-Mar-10 22:53
sanforjackass10-Mar-10 22:53 
GeneralRe: Fast execution Pin
harold aptroot10-Mar-10 22:57
harold aptroot10-Mar-10 22:57 
GeneralRe: Fast execution Pin
sanforjackass10-Mar-10 22:59
sanforjackass10-Mar-10 22:59 
GeneralRe: Fast execution Pin
harold aptroot10-Mar-10 23:02
harold aptroot10-Mar-10 23:02 
GeneralRe: Fast execution Pin
sanforjackass10-Mar-10 23:04
sanforjackass10-Mar-10 23:04 
GeneralRe: Fast execution Pin
harold aptroot10-Mar-10 23:05
harold aptroot10-Mar-10 23:05 
GeneralRe: Fast execution Pin
Rob Philpott10-Mar-10 23:44
Rob Philpott10-Mar-10 23:44 
GeneralRe: Fast execution Pin
harold aptroot11-Mar-10 0:03
harold aptroot11-Mar-10 0:03 
GeneralRe: Fast execution [modified] Pin
Keith Barrow10-Mar-10 23:03
professionalKeith Barrow10-Mar-10 23:03 
AnswerRe: Fast execution Pin
Keith Barrow10-Mar-10 22:41
professionalKeith Barrow10-Mar-10 22:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.