【问题标题】:C# Where to store variable properties setter'sC# 变量属性设置器的存储位置
【发布时间】:2016-02-18 21:17:40
【问题描述】:

我有一个名为a 的控制变量,更具体地说是一个标签。我希望能够在使用其他一些公共变量的同时设置a 属性,我用一个简单的结构就可以做到这一点:

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

所以稍后我们可以这样做:

Username.ForeColor = UsernameProperties.ForeColor;

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

之后我继承了包含标签变量的类:

    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;
        }
    }

【问题讨论】:

  • 您可以创建一个扩展标签类的用户名类。这样你就可以创建一个用户名实例。这样会更好吗?
  • 你能检查我更新的问题你确定它会工作吗:P
  • 您可以尝试自己运行它,看看它是否会工作......

标签: c# class struct properties controls


【解决方案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;

【讨论】:

  • 请解释这是如何回答问题的
猜你喜欢
  • 2013-05-10
  • 2010-12-07
  • 2019-06-16
  • 1970-01-01
  • 1970-01-01
  • 2011-02-27
  • 1970-01-01
  • 2019-07-25
相关资源
最近更新 更多