unassigned variable - error in the code of C# -
while (rdr.read()) { imgno = rdr.getstring(0); } httpcontext.current.response.write(imgno);
this code generate error
(error 5 use of unassigned local variable 'imgno')
presumably declared variable above code so:
string imgno; while (rdr.read()) { imgno = rdr.getstring(0); } httpcontext.current.response.write(imgno);
the compiler can't guarantee loop ever entered. indeed, in situation rdr
returns no records, loop skipped. in case, imgno
never assigned value. since compiler can't guarantee it, code doesn't compile.
simply assign default value variable:
string imgno = string.empty;
Comments
Post a Comment