c# handle null byte array from mysql query
arrays, blob, byte, c#, mysql
Solution
How about this:
byte[] data = null;
Arrays are reference types so you can assign null to them. Later on you will be able see if data is null just like this:
if(data != null)
{
//there is data inside that array, you can go ahead and use it.
}
EDIT: simplification
You could simplicate your code like this:
byte[] data = DbReader.IsDbNull(2) ? null : (byte[])DbReader[2];
Problem
i have created an app that basically looks for blob records on a mysql server problem i have is that if for whatever reason the blob field is empty the app crashes. I thought on something like i currently have ``` byte[] data = (byte[])DbReader[2]; ``` but i was wondering if there is any way to do something like ``` if (DbReader.IsDbNull(2) byte[] data = /* DEFAULT VALUE */ else byte[] data = (byte[])DbReader[2]; ``` but can i set a default value?? everything ive tried fails :(