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

前端 未结 4 1541
南方客
南方客 2020-12-20 15:50

I Have this code segment in VB NET:

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

what is

4条回答
  •  青春惊慌失措
    2020-12-20 16:01

    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);
    

提交回复
热议问题