Click here to Skip to main content
15,888,579 members
Home / Discussions / C#
   

C#

 
GeneralRe: My vote of 5 Pin
OriginalGriff8-Mar-10 22:39
mveOriginalGriff8-Mar-10 22:39 
QuestionUnstoppable process from Task Manager Pin
Ihtesham8-Mar-10 21:03
Ihtesham8-Mar-10 21:03 
AnswerRe: Unstoppable process from Task Manager Pin
Calla8-Mar-10 21:10
Calla8-Mar-10 21:10 
GeneralRe: Unstoppable process from Task Manager Pin
Ihtesham8-Mar-10 21:13
Ihtesham8-Mar-10 21:13 
GeneralRe: Unstoppable process from Task Manager Pin
Calla8-Mar-10 22:07
Calla8-Mar-10 22:07 
GeneralRe: Unstoppable process from Task Manager Pin
Ihtesham8-Mar-10 22:19
Ihtesham8-Mar-10 22:19 
QuestionFinding the nearest value within a .txt file that is above another value Pin
suprsnipes8-Mar-10 18:37
suprsnipes8-Mar-10 18:37 
AnswerRe: Finding the nearest value within a .txt file that is above another value Pin
Calla8-Mar-10 20:03
Calla8-Mar-10 20:03 
When you read each value in your file, first check if the value you read is greater than the value you are interested in (in your example 4991). In case it is: calculate the difference between that number and 4991 and store the number and the result in memory in case it is the smallest difference so far. And just loop through all the numbers. In code something like this:
int num = 4991;
int tmp, res = 0;
int? diff = null;

foreach (string s in split)
{
   count++;
   tmp = int.Parse(s);
   levels[count] = tmp;

   if (tmp > num)
   {
      if (diff == null)
     diff = num;
  if ((tmp - num) < diff)
  {
     res = tmp;
     diff = tmp - num;
  }
   }
}
Console.WriteLine(res);


Could probably be done in a better way, but you get the idea.
Good Luck! Smile | :)
GeneralRe: Finding the nearest value within a .txt file that is above another value Pin
suprsnipes8-Mar-10 21:32
suprsnipes8-Mar-10 21:32 
GeneralRe: Finding the nearest value within a .txt file that is above another value Pin
Calla8-Mar-10 22:02
Calla8-Mar-10 22:02 
QuestionWhich option is better for Reading file. File.ReadAllText(fileName) OR StreamReader Pin
Nadia Monalisa8-Mar-10 15:55
Nadia Monalisa8-Mar-10 15:55 
AnswerRe: Which option is better for Reading file. File.ReadAllText(fileName) OR StreamReader Pin
Scott Dorman8-Mar-10 16:22
professionalScott Dorman8-Mar-10 16:22 
GeneralRe: Which option is better for Reading file. File.ReadAllText(fileName) OR StreamReader Pin
Nadia Monalisa8-Mar-10 17:24
Nadia Monalisa8-Mar-10 17:24 
GeneralRe: Which option is better for Reading file. File.ReadAllText(fileName) OR StreamReader Pin
Luc Pattyn8-Mar-10 17:45
sitebuilderLuc Pattyn8-Mar-10 17:45 
GeneralRe: Which option is better for Reading file. File.ReadAllText(fileName) OR StreamReader Pin
OriginalGriff8-Mar-10 22:37
mveOriginalGriff8-Mar-10 22:37 
GeneralRe: Which option is better for Reading file. File.ReadAllText(fileName) OR StreamReader Pin
Scott Dorman9-Mar-10 3:41
professionalScott Dorman9-Mar-10 3:41 
AnswerRe: Which option is better for Reading file. File.ReadAllText(fileName) OR StreamReader Pin
Luc Pattyn8-Mar-10 16:25
sitebuilderLuc Pattyn8-Mar-10 16:25 
GeneralRe: Which option is better for Reading file. File.ReadAllText(fileName) OR StreamReader Pin
Nadia Monalisa8-Mar-10 17:28
Nadia Monalisa8-Mar-10 17:28 
GeneralRe: Which option is better for Reading file. File.ReadAllText(fileName) OR StreamReader Pin
Luc Pattyn8-Mar-10 17:41
sitebuilderLuc Pattyn8-Mar-10 17:41 
AnswerRe: Which option is better for Reading file. File.ReadAllText(fileName) OR StreamReader Pin
PIEBALDconsult8-Mar-10 17:41
mvePIEBALDconsult8-Mar-10 17:41 
GeneralRe: Which option is better for Reading file. File.ReadAllText(fileName) OR StreamReader Pin
Luc Pattyn8-Mar-10 17:49
sitebuilderLuc Pattyn8-Mar-10 17:49 
GeneralRe: Which option is better for Reading file. File.ReadAllText(fileName) OR StreamReader Pin
PIEBALDconsult9-Mar-10 3:20
mvePIEBALDconsult9-Mar-10 3:20 
GeneralRe: Which option is better for Reading file. File.ReadAllText(fileName) OR StreamReader Pin
Luc Pattyn9-Mar-10 3:24
sitebuilderLuc Pattyn9-Mar-10 3:24 
GeneralRe: Which option is better for Reading file. File.ReadAllText(fileName) OR StreamReader Pin
PIEBALDconsult9-Mar-10 6:16
mvePIEBALDconsult9-Mar-10 6:16 
GeneralRe: Which option is better for Reading file. File.ReadAllText(fileName) OR StreamReader Pin
Luc Pattyn9-Mar-10 6:33
sitebuilderLuc Pattyn9-Mar-10 6:33 

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.