如何将 VB.NET 的 CType() 转换为 C#? [英] How do I translate VB.NET's CType() to C#?
本文介绍了如何将 VB.NET 的 CType() 转换为 C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 VB.NET 中有这个代码段:
I have this code segment in VB.NET:
CType(pbImageHolder.Image, Bitmap).SetPixel(curPoint.X, curPoint.Y, Color.Purple)
什么是 C# 中合适的代码?
What is appropriate code in C#?
推荐答案
在 VB.Net CType(object, type)
将对象强制转换为特定类型.
In VB.Net CType(object, type)
casts an object to a specific type.
在 C# 中有两种方法可以实现这一点:
There are two ways to accomplish this in 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);
这篇关于如何将 VB.NET 的 CType() 转换为 C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文