Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何设置属于类的图像控件属性?_C#_Image_Oop_Class_Controls - Fatal编程技术网

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,所以当您使用前者时,您实际上是在使用后者。在您的场景中,没有区别。尽管回答了您的一般问题,但我还是希望在构造函数中使用字段语法,因为该属性可能会影响当前实例的状态,而当前实例可能尚未初始化