Click here to Skip to main content
15,917,320 members
Home / Discussions / C#
   

C#

 
AnswerRe: FileSystemWatcher doesnt seem to be working on Win7 Pin
stancrm9-Sep-09 8:54
stancrm9-Sep-09 8:54 
GeneralRe: FileSystemWatcher doesnt seem to be working on Win7 Pin
Gareth H9-Sep-09 22:24
Gareth H9-Sep-09 22:24 
AnswerRe: FileSystemWatcher doesnt seem to be working on Win7 Pin
Jacobb Michael9-Sep-09 22:39
Jacobb Michael9-Sep-09 22:39 
GeneralRe: FileSystemWatcher doesnt seem to be working on Win7 Pin
Gareth H9-Sep-09 22:43
Gareth H9-Sep-09 22:43 
GeneralRe: FileSystemWatcher doesnt seem to be working on Win7 Pin
Jacobb Michael10-Sep-09 1:19
Jacobb Michael10-Sep-09 1:19 
Questionget rid of advertised shortcut Pin
Piratenwichtl20009-Sep-09 5:25
Piratenwichtl20009-Sep-09 5:25 
AnswerRe: get rid of advertised shortcut Pin
Dave Kreskowiak9-Sep-09 6:25
mveDave Kreskowiak9-Sep-09 6:25 
QuestionExcel 2000 vs Excel 2007 Pin
jashimu9-Sep-09 3:50
jashimu9-Sep-09 3:50 
AnswerRe: Excel 2000 vs Excel 2007 Pin
Not Active9-Sep-09 4:32
mentorNot Active9-Sep-09 4:32 
GeneralRe: Excel 2000 vs Excel 2007 Pin
jashimu9-Sep-09 5:29
jashimu9-Sep-09 5:29 
GeneralRe: Excel 2000 vs Excel 2007 Pin
DaveyM699-Sep-09 5:35
professionalDaveyM699-Sep-09 5:35 
GeneralRe: Excel 2000 vs Excel 2007 Pin
dan!sh 9-Sep-09 6:23
professional dan!sh 9-Sep-09 6:23 
GeneralRe: Excel 2000 vs Excel 2007 Pin
jashimu9-Sep-09 6:54
jashimu9-Sep-09 6:54 
GeneralRe: Excel 2000 vs Excel 2007 Pin
Mirko19809-Sep-09 21:42
Mirko19809-Sep-09 21:42 
AnswerHelp : bcp.exe blocked !!!! [Solved] Pin
Guy.Rostand9-Sep-09 3:36
Guy.Rostand9-Sep-09 3:36 
QuestionMore than one Client !!!! Pin
CRAZYCRICKET2259-Sep-09 2:36
CRAZYCRICKET2259-Sep-09 2:36 
AnswerRe: More than one Client !!!! Pin
SeMartens9-Sep-09 3:30
SeMartens9-Sep-09 3:30 
AnswerRe: More than one Client !!!! Pin
April Fans22-Sep-09 17:28
April Fans22-Sep-09 17:28 
QuestionNetwork Scanner Pin
deviao9-Sep-09 2:21
deviao9-Sep-09 2:21 
AnswerRe: Network Scanner Pin
Richard MacCutchan9-Sep-09 3:10
mveRichard MacCutchan9-Sep-09 3:10 
QuestionBinarySearch checks same element Pin
Caio19859-Sep-09 1:22
Caio19859-Sep-09 1:22 
Hello,

I've created a function which walks pixel by pixel on an image, storing the pixel color on a Pixel Class.

The software was doing much processing on this loop because each time a new Pixel was found an instance of a Pixel Class was created. Then, I decided to declare a single Pixel Class instance outside the loop and then modify only its values inside the loop and then add it to the list of Pixel Class.

The problem started appearing after I did that. Now, when I try using BinarySearch on a List<t> it always returns me 0. It seems that C# is checking the Pixel Class instead of its content, which is what I want.

I tried to create an IComparer<t> to check the Pixel Class value but it doesn't work since the function always receive the same Class in both parameters, so the check is in vain.

So here I leave the question: How can I use BinarySearch on a class which only changes its content but not its address?

The (pseudo)code below illustrates the code before and after the changes:

BEFORE:

for (int x...)
 for(int y...) 
 {
  Pixel p = new Pixel();
  p.value = ...
  ...
  int pos = pixels.BinarySearch(p);
 }


AFTER:

Pixel p = new Pixel();
PixelComparer pComp = new PixelComparer();
for (int x...)
 for(int y...) 
 {
  p.value = ...
  ...
  int pos = pixels.BinarySearch(p);
  int pos = pixels.BinarySearch(p, pComp);
  //now both calls above returns fails!!!
 }


public class PixelComparer : IComparer<Pixel>
{
 public int Compare(Pixel a, Pixel b)
 {
  //a.value and b.value is always the same value!!!
  Console.WriteLine("{0} x {1}", a.value, b.value);
  return a.value.CompareTo(b.value);
 }
}


Thanks in advance,
AnswerRe: BinarySearch checks same element Pin
Luc Pattyn9-Sep-09 1:30
sitebuilderLuc Pattyn9-Sep-09 1:30 
GeneralRe: BinarySearch checks same element Pin
Caio19859-Sep-09 1:49
Caio19859-Sep-09 1:49 
GeneralRe: BinarySearch checks same element Pin
Luc Pattyn9-Sep-09 2:11
sitebuilderLuc Pattyn9-Sep-09 2:11 
GeneralRe: BinarySearch checks same element Pin
Caio19859-Sep-09 3:03
Caio19859-Sep-09 3:03 

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.