C# 如何设置属于类的图像控件属性?
我有一个图像控件作为类的属性之一C# 如何设置属于类的图像控件属性?,c#,image,oop,class,controls,C#,Image,Oop,Class,Controls,我有一个图像控件作为类的属性之一 public Image ImageControl { get { return _imgControl; } set { _imgControl = value; } } 在类构造函数中,使用此选项是否正确 ImageControl.Width = bi.PixelWidt
public Image ImageControl
{
get
{
return _imgControl;
}
set
{
_imgControl = value;
}
}
在类构造函数中,使用此选项是否正确
ImageControl.Width = bi.PixelWidth;
ImageControl.Height = bi.PixelHeight;
ImageControl.Source = bi;
还是这个
_imgControl.Width = bi.PixelWidth;
_imgControl.Height = bi.PixelHeight;
_imgControl.Source = bi;
我只是想知道,因为ImageControl本身是一个包含属性的控件,它是如何影响_ImageControl的值的?ImageControl属性只是返回_imgControl,所以当您使用前者时,您实际上是在使用后者。在您的场景中,没有区别。尽管回答了您的一般问题,但我还是希望在构造函数中使用字段语法,因为该属性可能会影响当前实例的状态,而当前实例可能尚未初始化