C# 使用C更新通用列表项#

C# 使用C更新通用列表项#,c#,list,C#,List,我不知道如何更新一个项目的通用列表后,审查所有的问题张贴在这里,我很抱歉。我的问题是: 我有这样的结构: List<LineInfo> Lines = new List<LineInfo>(); LineInfo LInfo; struct LineInfo { public int line; public int WO; public string Brand; public st

我不知道如何更新一个项目的通用列表后,审查所有的问题张贴在这里,我很抱歉。我的问题是:

我有这样的结构:

List<LineInfo> Lines = new List<LineInfo>();
    LineInfo LInfo;
    struct LineInfo
    {
        public int line;
        public int WO;
        public string Brand;
        public string Model;
        public string Customer;
        public int Qty;
        public int Target;
        public string Leader;
        public string Start;
        public string End;
        public int Percent;
    }      
请告知,谢谢。

只要

LInfo.Percent = Convert.ToInt32((RealProduced / DesireProd) * 100);
Lines[aCurrentLine] = LInfo;
应该有用。。。但请不要使用公共字段或可变结构。两者在可维护性和意外影响方面都很糟糕

在C#中创建的大多数类型都可能是类,但很少需要创建值类型(struct)。你应该确保你意识到这一点

类似地,C#中的字段几乎总是私有的。它们应该是该类型的实现细节,而不是其公共API的一部分。-C#3中自动实现的属性使它们几乎像字段一样紧凑,如果您只需要一个微不足道的属性的话。

LInfo.Percent = Convert.ToInt32((RealProduced / DesireProd) * 100);
Lines[aCurrentLine] = LInfo;
应该有用。。。但请不要使用公共字段或可变结构。两者在可维护性和意外影响方面都很糟糕

在C#中创建的大多数类型都可能是类,但很少需要创建值类型(struct)。你应该确保你意识到这一点


类似地,C#中的字段几乎总是私有的。它们应该是该类型的实现细节,而不是其公共API的一部分。-C#3中自动实现的属性使它们几乎像字段一样紧凑,如果您只需要一个微不足道的属性的话。

我只有一个缺点。可变结构是邪恶的。尽量避免

行[aCurrentLine]=LInfo


您将无法访问
行[aCurrentLine]。百分比
,因为它只更新了一个临时副本。

我只有一个缺点。可变结构是邪恶的。尽量避免

行[aCurrentLine]=LInfo


您将无法访问
行[aCurrentLine]。百分比
,因为它只更新临时副本。

用于使用网格视图更新常规列表记录。只需输入此代码

 List<Address> people = (List<Address>)Session["People"];
        people[e.RowIndex].DoorNo = ((TextBox)grdShow.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
        people[e.RowIndex].StreetName = ((TextBox)grdShow.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
        people[e.RowIndex].City = ((TextBox)grdShow.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
        people[e.RowIndex].PhoneNo = ((TextBox)grdShow.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
        grdShow.EditIndex = -1;
        grdShow.DataSource = people;
        grdShow.DataBind();
生成列表()的集合

private void GenerateList()
{
if(会话[“人员”]!=null)
{
列表人员=(列表)会话[“人员”];
地址a1=新地址();
a1.DoorNo=txtDoorno.Text;
a1.StreetName=txtStreetName.Text;
a1.City=txtCityname.Text;
a1.PhoneNo=txtPhoneno.Text;
新增(a1);
会话[“人”]=人;
grdShow.DataSource=人;
grdShow.DataBind();
}
}

用于使用网格视图更新通用列表记录。只需输入此代码

 List<Address> people = (List<Address>)Session["People"];
        people[e.RowIndex].DoorNo = ((TextBox)grdShow.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
        people[e.RowIndex].StreetName = ((TextBox)grdShow.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
        people[e.RowIndex].City = ((TextBox)grdShow.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
        people[e.RowIndex].PhoneNo = ((TextBox)grdShow.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
        grdShow.EditIndex = -1;
        grdShow.DataSource = people;
        grdShow.DataBind();
生成列表()的集合

private void GenerateList()
{
if(会话[“人员”]!=null)
{
列表人员=(列表)会话[“人员”];
地址a1=新地址();
a1.DoorNo=txtDoorno.Text;
a1.StreetName=txtStreetName.Text;
a1.City=txtCityname.Text;
a1.PhoneNo=txtPhoneno.Text;
新增(a1);
会话[“人”]=人;
grdShow.DataSource=人;
grdShow.DataBind();
}
}

太棒了!谢谢,关于可变结构,我需要阅读;)令人惊叹的!谢谢,关于可变结构,我需要阅读;)
GenerateList();//call the method GenerateList();
private void GenerateList()
    {
        if (Session["People"] != null)
        {

            List<Address> people = (List<Address>)Session["People"];

            Address a1 = new Address();

            a1.DoorNo = txtDoorno.Text;
            a1.StreetName = txtStreetName.Text;
            a1.City = txtCityname.Text;
            a1.PhoneNo = txtPhoneno.Text;
            people.Add(a1);
            Session["People"] = people;
            grdShow.DataSource = people;
            grdShow.DataBind();
        }
    }