我在 VB.NET 中有这段代码:
CType(pbImageHolder.Image, Bitmap).SetPixel(curPoint.X, curPoint.Y, Color.Purple)
什么是 C# 中合适的代码?
最佳答案
在 VB.Net 中,CType(object, type)
将对象转换为特定类型。
在 C# 中有两种方法可以实现这一点:
Bitmap image = pbImageHolder.Image as Bitmap;
image.SetPixel(curPoint.X, curPoint.Y, Color.Purple);
或
Bitmap image = (Bitmap)(pbImageHolder.Image);
image.SetPixel(curPoint.X, curPoint.Y, Color.Purple);
关于c# - 如何将 VB.NET 的 CType() 转换为 C#?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12249528/