C#存储变量属性setter的位置

时间:2016-02-18 21:17:41

标签: c# class struct properties controls

我有一个名为a的控件变量,更具体地说是Label。我希望能够在使用其他一些公共变量的同时设置a属性,我用这样的方法完成了一个简单的结构:

    public Label Username = new Label();
    public struct UsernameProperties
    {
        public Color BackColor;
        public Color ForeColor;
        public int FontSize;
    }

以后我们可以这样做:

Username.ForeColor = UsernameProperties.ForeColor;

虽然我们可以从其他类设置UsernameProperties.ForeColor;。结构是存储这些变量的最佳位置吗?或者有一些已经构建的结构将完成这项工作。

在此之后,我继承了包含Label变量的类:

    public class UsersProperties
    {
//some other variables
        public Label Username = new Label();
        public struct UsernameProperties
        {
            public string Name;
            public Color BackColor;
            public Color ForeColor;
            public int FontSize;
        }
    }

    public class Player : UsersProperties
    {
        public Player(Label Username)
        {
            Username.Text = UsernameProperties.Name;
        }
    }

1 个答案:

答案 0 :(得分:-1)

var person = {
    firstName: "Celcom",
    lastName : "Africa",

    get fullName() {
        return this.firstName + " " + this.lastName;
    }
};

// Display data from the object using a getter: 
document.getElementById("demo").innerHTML = person.fullName;