Click here to Skip to main content
15,913,162 members
Home / Discussions / C#
   

C#

 
GeneralCystal Report Chart questions-C# Winforms using cystal report Pin
Anonymous29-Jun-04 9:40
Anonymous29-Jun-04 9:40 
QuestionC# missing anonymous classes? Pin
vista2729-Jun-04 8:39
vista2729-Jun-04 8:39 
AnswerRe: C# missing anonymous classes? Pin
Judah Gabriel Himango29-Jun-04 8:49
sponsorJudah Gabriel Himango29-Jun-04 8:49 
GeneralRe: C# missing anonymous classes? Pin
vista2729-Jun-04 9:22
vista2729-Jun-04 9:22 
GeneralRe: C# missing anonymous classes? Pin
Judah Gabriel Himango29-Jun-04 9:45
sponsorJudah Gabriel Himango29-Jun-04 9:45 
AnswerRe: C# missing anonymous classes? Pin
Heath Stewart29-Jun-04 9:05
protectorHeath Stewart29-Jun-04 9:05 
Generalmemcmp in C# Pin
BrcKcc29-Jun-04 8:29
BrcKcc29-Jun-04 8:29 
GeneralRe: memcmp in C# Pin
Heath Stewart29-Jun-04 9:45
protectorHeath Stewart29-Jun-04 9:45 
There really isn't a way as fast as memcmp, so if you need that kind of performance, you can always P/Invoke it:
using System;
using System.Runtime.InteropServices;

class Test
{
  static void Main()
  {
    byte[] b1 = new byte[10];
    byte[] b2 = new byte[10];

    for (int i=0; i<b1.Length; i++)
      b1[i] = b2[i] = Convert.ToByte(i);

    Console.WriteLine("Equals:        " + b1.Equals(b2));
    Console.WriteLine("Object.Equals: " + Object.Equals(b1, b2));
    Console.WriteLine("memcmp:        " + Compare(b1, b2));
  }

  static bool Compare(byte[] b1, byte[] b2)
  {
    IntPtr retval = memcmp(b1, b2, new IntPtr(b1.Length));
    return retval == IntPtr.Zero;
  }

  [DllImport("msvcrt.dll")]
  static extern IntPtr memcmp(byte[] b1, byte[] b2, IntPtr count);
}
This would print:
Equals:        False
Object.Equals: False
memcmp:        True
By doing this you sacrific portability, however. If you don't need that kind of performance, use a simple for (not foreach, which is slower) loop and compare each byte using the == equivalency operator.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: memcmp in C# Pin
BrcKcc29-Jun-04 9:54
BrcKcc29-Jun-04 9:54 
GeneralRe: memcmp in C# Pin
Werdna30-Jun-04 5:53
Werdna30-Jun-04 5:53 
GeneralRe: memcmp in C# Pin
BrcKcc30-Jun-04 6:24
BrcKcc30-Jun-04 6:24 
GeneralRe: memcmp in C# Pin
Werdna30-Jun-04 6:47
Werdna30-Jun-04 6:47 
GeneralRe: memcmp in C# Pin
BrcKcc30-Jun-04 7:02
BrcKcc30-Jun-04 7:02 
QuestionWhats an RVA ? Pin
Peter Vertes29-Jun-04 8:27
Peter Vertes29-Jun-04 8:27 
AnswerRe: Whats an RVA ? Pin
Peter Vertes29-Jun-04 8:33
Peter Vertes29-Jun-04 8:33 
AnswerRe: Whats an RVA ? Pin
Heath Stewart29-Jun-04 9:49
protectorHeath Stewart29-Jun-04 9:49 
GeneralRe: Whats an RVA ? Pin
Peter Vertes29-Jun-04 10:28
Peter Vertes29-Jun-04 10:28 
GeneralTwo problems with MDI Pin
Metzler29-Jun-04 7:11
Metzler29-Jun-04 7:11 
GeneralUsing DataBinding with a user control Pin
Brett Slaski29-Jun-04 6:39
Brett Slaski29-Jun-04 6:39 
GeneralLDAP Active directory Pin
robmays29-Jun-04 4:11
robmays29-Jun-04 4:11 
GeneralRe: LDAP Active directory Pin
Heath Stewart29-Jun-04 5:37
protectorHeath Stewart29-Jun-04 5:37 
GeneralRe: LDAP Active directory Pin
robmays2-Jul-04 21:48
robmays2-Jul-04 21:48 
GeneralDataset Filter Interger Pin
Antonius_r329-Jun-04 4:11
Antonius_r329-Jun-04 4:11 
GeneralRe: Dataset Filter Interger Pin
Dave Kreskowiak29-Jun-04 5:04
mveDave Kreskowiak29-Jun-04 5:04 
GeneralRe: Dataset Filter Interger Pin
Antonius_r329-Jun-04 5:47
Antonius_r329-Jun-04 5:47 

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.