Click here to Skip to main content
15,906,625 members
Home / Discussions / C#
   

C#

 
QuestionTest is a form is closed Pin
baranils12-May-08 10:14
baranils12-May-08 10:14 
AnswerRe: Test is a form is closed [modified] Pin
Anthony Mushrow12-May-08 10:36
professionalAnthony Mushrow12-May-08 10:36 
GeneralRe: Test is a form is closed Pin
baranils12-May-08 18:58
baranils12-May-08 18:58 
AnswerRe: Test is a form is closed Pin
Christian Graus12-May-08 12:08
protectorChristian Graus12-May-08 12:08 
Questionint[] reference issue Pin
shamidi12-May-08 9:43
shamidi12-May-08 9:43 
AnswerRe: int[] reference issue Pin
Ed.Poore12-May-08 10:13
Ed.Poore12-May-08 10:13 
GeneralRe: int[] reference issue Pin
shamidi12-May-08 10:33
shamidi12-May-08 10:33 
GeneralRe: int[] reference issue Pin
Ed.Poore12-May-08 12:28
Ed.Poore12-May-08 12:28 
First question are both guaranteed to be the same length?
Secondly how do you mean equal, both have the same values in the same positions or simply contain the same integers but in different locations?

If 1 is false and 2 implies both in the same order and value then the fastest way would be:
if (x.Length != y.Length)
  return false;
for (int i = 0; i < x.Length; i++)
{
  if (x[i] != y[i])
    return false;
}
return true

This code will work based on the fact that they are equal under the condition that both arrays have the same values at the same indicies.  Obviously you could tailor this algorithm slightly because if you know differing values are likely to occur at the end of the array then you can loop backwards thus hitting the difference first.

You will have to loop regardless, even if you went down to assembly then the processors will only be able to handle a maximum (I think) of a 64-bit bitwise operation (if you're lucky) so they will have to loop anyway.

If you're still having issues with performance, is your code running on a multicore processor?  If so and you still want to go through C# (note I have seen some statistics where C# can out perform C++ but for the life of me I can't remember which areas they are, so you might as well stick with it); anyway if you are running on a multicore then you might want to take a look at the Parallel Extensions for .NET[^].  Which can through a "simple" syntax optimise your loops to run on multicore processors (or leave it alone for single cores).


I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder

AnswerRe: int[] reference issue Pin
#realJSOP12-May-08 10:16
professional#realJSOP12-May-08 10:16 
GeneralRe: int[] reference issue Pin
shamidi12-May-08 10:35
shamidi12-May-08 10:35 
GeneralRe: int[] reference issue Pin
Anthony Mushrow12-May-08 10:41
professionalAnthony Mushrow12-May-08 10:41 
GeneralRe: int[] reference issue Pin
#realJSOP12-May-08 10:50
professional#realJSOP12-May-08 10:50 
AnswerRe: int[] reference issue Pin
Guffa12-May-08 21:28
Guffa12-May-08 21:28 
GeneralRe: int[] reference issue Pin
#realJSOP13-May-08 1:20
professional#realJSOP13-May-08 1:20 
JokeRe: int[] reference issue Pin
Guffa13-May-08 2:05
Guffa13-May-08 2:05 
AnswerRe: int[] reference issue Pin
Le centriste14-May-08 6:24
Le centriste14-May-08 6:24 
QuestionHow to retrive the value? Pin
Luckie12-May-08 9:04
Luckie12-May-08 9:04 
AnswerRe: How to retrive the value? Pin
Ennis Ray Lynch, Jr.12-May-08 9:09
Ennis Ray Lynch, Jr.12-May-08 9:09 
GeneralRe: How to retrive the value? Pin
Luckie12-May-08 9:18
Luckie12-May-08 9:18 
AnswerRe: How to retrive the value? Pin
led mike12-May-08 9:18
led mike12-May-08 9:18 
GeneralRe: How to retrive the value? Pin
Luckie12-May-08 9:26
Luckie12-May-08 9:26 
GeneralRe: How to retrive the value? Pin
KaptinKrunch12-May-08 10:31
KaptinKrunch12-May-08 10:31 
GeneralRe: How to retrive the value? Pin
led mike12-May-08 10:32
led mike12-May-08 10:32 
GeneralRe: How to retrive the value? Pin
Luckie12-May-08 10:47
Luckie12-May-08 10:47 
GeneralRe: How to retrive the value? Pin
led mike13-May-08 5:50
led mike13-May-08 5:50 

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.