通过类在C#中循环,并改变每个对象的属性值 [英] Loop through class in C# and change property value of each object

查看:402
本文介绍了通过类在C#中循环,并改变每个对象的属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在书面方式一个Asp.net仪表板应用程序。当我加载主页我捕捉控制设置和动态地创建仪表,图表,图像等。并将其加载到单元格在一个HTML表。将要供给至各控制数据将更新每3秒。我目前存储在一个名为BoldGauge类我压力表。内部的类的存在用于GaugeValue一个属性,这将需要每3秒进行更新。我怎么能遍历类,并在运行时所创建的每个计更改值?我的阶级是这样的:

I am writting a dashboard application in Asp.net. When I load the main page I capture control settings and dynamically create gauges, charts, images, etc.. and load them to a cell in an HTML table. The data that will be fed to each control will update every 3 seconds. I currently store my gauges in a class called BoldGauge. Inside of that class there is a property for GaugeValue, that will need to be updated every 3 seconds. How can I loop through the class and change the values at runtime for each gauge that was created? My class looks like this:

public class BoldGauge
{
    private ASPxGaugeControl m_Gauge;
    private int m_GaugeTimer;
    private string m_GaugeValue;
    private string m_GaugeDataType;
    private float m_GaugeMinValue;
    private float m_GaugeMaxValue;

    public BoldGauge(ASPxGaugeControl Gauge, string GaugeValue, string GaugeDataType, float GaugeMinValue, float GaugeMaxValue)
    {
        m_Gauge = Gauge;
        m_GaugeValue = GaugeValue;
        m_GaugeDataType = GaugeDataType;
        m_GaugeMinValue = GaugeMinValue;
        m_GaugeMaxValue = GaugeMaxValue;

    }

    public string GaugeValue
    {
        get
        {
            return m_GaugeValue;
        }
        set
        {
            m_GaugeValue = value;
        }
    }

    public int GaugeTimer
    {
        get
        {
            return m_GaugeTimer;
        }
        set
        {
            m_GaugeTimer = value;
        }
    }

    public string GaugeDataType
    {
        get
        {
            return m_GaugeDataType;
        }
        set
        {
            m_GaugeDataType = value;
        }
    }

    public ASPxGaugeControl Gauge
    {
        get
        {
            return m_Gauge;
        }
        set
        {
            m_Gauge = value;
        }
    }

    public float GaugeMinValue
    {
        get
        {
            return m_GaugeMinValue;
        }
        set
        {
            m_GaugeMinValue = value;
        }
    }

    public float GaugeMaxValue
    {
        get
        {
            return m_GaugeMaxValue;
        }
        set
        {
            m_GaugeMaxValue = value;
        }
    }
}

在主页我产生了新的对象这样的:

On the main page I generate the new object Like this:

newBoldGauge = new BoldGauge(boldGaugeControl, gaugeValue, controlData, minimumGaugeValue, MaximumGaugeValue);

感谢。

推荐答案

创建 BoldGague 对象的集合,然后通过集合并进行必要的修改。

Create a collection of BoldGague objects, then loop through that collection and make the necessary changes.

List<BoldGague> gagues = new List<BoldGague>();

foreach(BoldGague gague in gagues)
{
    // change values here.
}

这篇关于通过类在C#中循环,并改变每个对象的属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆