Neither alternative is good for situations when something does not exist: returning an empty array of bytes is wrong, because the users cannot distinguish between finding an image that is actually empty, and not finding an image. Returning null is slightly better, but the users may forget to null-check the return.
Two alternatives that work better are returning a not found result as a bool while setting the result in an out parameter, and throwing an exception. Both approaches make the "image not found" condition explicit to the users of your API, making it harder to miss.
bool TryLookUpImage(string name, out byte[] image) {
...
}
...
byte[] image;
if (TryLookUpImage(imageName, out image)) {
// Display image
} else {
// Display error
}
byte[]reference which is null? No need to usebyte[].byte[]is reference type. You can do returnnulldirectly:byte[] Method() { return null; }.byte?[]means that you will create array of nullable bytes (so any / all of byte could be null, ) - that make no sense in this case.