B
BC
Hi all,
I have a method that accepts a string as the parameter. This can be a
base64 image string, or just a normal string. Currently to test whether
it's a image string or just a normal string, I used try and catch:
private void MyMethod(string str){
try{
// If not exception is cought, then it is an image string
MemoryStream stream = new MemoryStream(Convert.FromBase64String(str));
Bitmap bitmap = new Bitmap(stream);
...
}
catch{
// If exception is cought, then I assumed it is a normal string
string normalStr = str;
...
}
}
The codes work fine and gave me what I want. However, some while ago an
article I read mentioned that using try and catch could slow down
performance. My question is that if I don't use try and catch to test
the string, what is the alternative ways I can do this? Also, about the
performance thing, how true is it?
Cheers,
Benny
I have a method that accepts a string as the parameter. This can be a
base64 image string, or just a normal string. Currently to test whether
it's a image string or just a normal string, I used try and catch:
private void MyMethod(string str){
try{
// If not exception is cought, then it is an image string
MemoryStream stream = new MemoryStream(Convert.FromBase64String(str));
Bitmap bitmap = new Bitmap(stream);
...
}
catch{
// If exception is cought, then I assumed it is a normal string
string normalStr = str;
...
}
}
The codes work fine and gave me what I want. However, some while ago an
article I read mentioned that using try and catch could slow down
performance. My question is that if I don't use try and catch to test
the string, what is the alternative ways I can do this? Also, about the
performance thing, how true is it?
Cheers,
Benny