How do I translate VB.Net's CType() to C#

I Have this code segment in VB NET:

CType(pbImageHolder.Image, Bitmap).SetPixel(curPoint.X, curPoint.Y, Color.Purple)

what is appropriate code in C#?

Thank you in advance.

Answers


In VB.Net CType(object, type) casts an object to a specific type.

There are two ways to accomplish this in C#:

Bitmap image = pbImageHolder.Image as Bitmap;
image.SetPixel(curPoint.X, curPoint.Y, Color.Purple);

or

Bitmap image = (Bitmap)(pbImageHolder.Image);
image.SetPixel(curPoint.X, curPoint.Y, Color.Purple);

((Bitmap)pbImageHolder.Image).SetPixel(curPoint.X, curPoint.Y, Color.Purple)

Hi this is the code after conversion VB to C# code:

((Bitmap)pbImageHolder.Image).SetPixel(curPoint.X, curPoint.Y, Color.Purple);

And if you want code conversion from VB to C# and vice verse go through the following link: http://www.developerfusion.com/tools/convert/vb-to-csharp/


Need Your Help

Can I constrain a type family?

haskell

In this recent answer of mine, I happened to crack open this old chestnut (a program so old, half of it was written in the seventeenth century by Leibniz and written on a computer in the seventies ...

CSS: Center block, but align contents to the left

css alignment center

I want a whole block to be centered in its parent, but I want the contents of the block to be left aligned.