c# - Cannot apply indexing to an expression of type 'IntPtr' == IntPtr ptr1 = [...] --> ptr1[0] -


i found code snippet want implement. problem 1 function isn't running. cannot apply indexing expression of type 'intptr'

        fixed (byte* numref = this.tribuf)         {             (int = 0; < num; i++)             {                 item = this.trihash.getitem(ch + s.substring(i, 3));                 if (item != null)                 {                     this.trigramchecked += item.count;                     foreach (int num3 in item)                     {                         if ((num3 != id) && (numref[num3] < 0xff))                         {                             intptr ptr1 = (intptr) (numref + num3);                             /* todo: error */                             ptr1[0] = (intptr) ((byte) (ptr1[0] + 1));                         }                     }                 }             }         } 

regards chris

as said in comment, try avoid unsafe code in first place, looks it's trying do:

if ((num3 != id) && (numref[num3] < 0xff)) {     numref[num3]++; } 

or perhaps more efficiently (to read numref[num3] once):

if (num3 != id) {     byte value = numref[num3];     if (value < 0xff)     {         numref[num3] = (byte) (value + 1);     } } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -