.net - Object reference not set to an instance of an object in switch C# -


i have error in switch instruction, don't know why. @ main class:

            try {               var result = string.join(" ",file.readallbytes(args[0]).select(x => x.tostring("x")));             console.writeline(result);             asm asm = new asm();              if(result != null) asm.exec(result); //error here?         }         catch(exception ex) {             console.writeline(ex.message);         } 

and asm class. think error in exec method , in switch-case instruction:

public class asm {     public void exec(string ex)      {         if (ex == null)             console.writeline("asm opcode null!");         string[] = ex.split(' ');         int = 0;         while (i<a.length)         {             switch (a [i])             {                 case "af":  //hlt                     environment.failfast("hlt");                     break;                 case "ab":  //write                     i++;                     string memorysegment = a[i];                     i++;                     int memoryvalue = convert.toint32(a[i]);                     if(memorysegment == "f0") memory.write("0xc00",memoryvalue);                     else if (memorysegment == "f1") memory.write("0x100",memoryvalue);                     else if (memorysegment == "f2") memory.write("0x200",memoryvalue);                     else if (memorysegment == "f3") memory.write("0xa00",memoryvalue);                     else if (memorysegment == "f4") memory.write("0xb00",memoryvalue);                     break;             }             i++;         }     } 

in console see ab f1 19 af object reference not set instance of object how away error? code write hex code of file, arguments asm.exec method (result) not null, not readable method. thanks, sorry bad english.

i can't sure reason of exception, should point fact inside case "ab" increment value of i without checking if new value still inside bounds of array a.

if hit ab case last byte of array have exception (though should indexoutofrange exception).


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -