c# - How to Check byte array empty or not? -


here m downloading word file getsourceattachment method.when method returning empty bytes byte attachment array gives error(object reference not set instance of object).when m checking length of attachment in if condition giving error. can 1 me default initialize byte array check length.

try {         byte[] attachment = null ;          string extension = string.empty;         clsportalmanager objportalmanager = new clsportalmanager();         attachment = objportalmanager.getsourceattachment(convert.toint32(hdnsourceid.value), out extension);         if (attachment.length > 0 && attachment != null)         {             downloadattachment("attacment", attachment, extension);         }         else         {             clientscript.registerstartupscript(typeof(page), "symbolerror", "<script type='text/javascript'>alert('attachment not uploaded !');</script>");         }             } catch {  } 

just do

if (attachment != null  && attachment.length > 0) 

from && operator

the conditional-and operator (&&) performs logical-and of bool operands, but evaluates second operand if necessary.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -