comparing strings in c# which calls C dll -


(day 2 of learning c#) passing buffer c dll c#. c func copies string "text" buffer. in c# code, compare "text" what's in buffer , doesn't compare equal. missing?

    extern "c" __declspec( dllexport )           int  cfunction(char *plotinfo, int buffersize)      {         strcpy(plotinfo, "text");         return(0);     } 

c#

using system; using system.collections.generic; using system.linq; using system.text; using system.runtime.interopservices;   namespace consoleapplication1 {     class program     {         [dllimport("mcdll.dll", callingconvention = callingconvention.cdecl,                                                       charset=charset.ansi)]         public static extern int cfunction(stringbuilder thestring, int bufsize);          static void main(string[] args)         {             stringbuilder s = new stringbuilder(55);             int result = cfunction(s, 55);             console.writeline(s);              string zz = "text";             if (s.equals(zz))                 console.writeline( "strings compare equal");             else                 console.writeline("not equal");              console.readline();         }     } } 

s stringbuilder, while zz string.

try comparing

s.tostring().equals(zz); 

generally, equals() performs reference comparison reference types. classes (such string) override equals() allow strings contain same characters considered equal (though performance purposes, believe actual implementation first checks reference equality, compares contents of each string).

your current code calling .equals() method of stringbuilder.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -