I'm quite jumping between the two languages. In the morning at the university I'm usually programming Java and then in
the afternoon at work I'm programming in C#.net. This can be quite interesting and also be an advantage to have this
kind of view to both of the languages (and also the according expertise). My personal opinion is that usually good
programmers emerge from the Java world since I find it highly educational.
Anyway, having this kind of view
however, you often then come across funny things you coded such as the following :)
I just needed a way for
reading in an image as a byte[]. As a Java programmer, hearing byte[], you would immediately think of some stream
etc...and so the following came out:
private byte[] ConvertImageToByte(Image toConvert, ImageFormat format)
{
byte[] result;
using (MemoryStream ms = new MemoryStream())
{
toConvert.Save(ms, format);
result = ms.ToArray();
}
if (result.Length == 0)
result = null;
return result;
}
Well
encapsulated and it worked perfectly but the solution could have been so simple ;)
byte[] imageData = File.ReadAllBytes(tifFilePath);
Questions? Thoughts? Hit me up
on Twitter