We have two images.
Image tempImage = new Image();
tempImage.width = 500;
Image tempImage2 = new Image();
tempImage2.width = 1000;
I want to compare the widthes of these images and find image with greater width:
I tried following:
if (tempImage.Width < tempImage2.Width) Response.write("width of tempImage2 is bigger");
else Response.write("width of tempImage1 is bigger");
Compiler gets an error: cannot compare these two values.
I tried following:
Image1.Width = (int)Math.Max(Convert.toDouble(tempImage.Width),Convert.toDouble(tempImage2.Width));
Response.Write("max width is " + Image1.Width);
Compiler couldn’t convert width to double.
So how to compare the width of images and find the image with bigger width?
You’re getting the error because the Width property of an Image is a Unit structure type, not a scalar and there is no comparison operator implemented for it.
will work, but that comparison is strictly only valid if the Type of the unit is the same. In your sample, it defaults to pixel, but in a more general case, you’d need to make sure you’re comparing values of the same unit.