C# 将具有预定义结构的列表作为参数传递给其他表单

C# 将具有预定义结构的列表作为参数传递给其他表单,c#,winforms,parameters,C#,Winforms,Parameters,我在一些链接中看到过这个问题,比如,但我相信我的情况有点不同 我想把一个列表传给第二个表单,它将被上传到数据库中 名单的结构如下: public struct GraphData { public double Temp1; public double Temp2; public DateTime Date; public string Type; } 列表的填充方式如下所示: for (int i

我在一些链接中看到过这个问题,比如,但我相信我的情况有点不同

我想把一个列表传给第二个表单,它将被上传到数据库中

名单的结构如下:

    public struct GraphData
    {
        public double Temp1;
        public double Temp2;
        public DateTime Date;
        public string Type;
    }
列表的填充方式如下所示:

    for (int i = startIndex; i <= endIndex; i++)
    {
        GraphData update = _listData[i];
        update.Type = type;
        _listData[i] = update;
        chart1.Series[0].Points[i].Color = color;

        // add to a list so we can save on the DB if the user wants
        PointsAndCycles.Add(new GraphData()
        {
            Temp1 = update.Temp1,
            Temp2 = update.Temp2,
            Date = update.Date,
            Type = update.Type
            // CAN I ALSO HAVE THE ID?
        });

    }
public void button1_Click(object sender, EventArgs e)
{
    Database.SavePointsAndCyclesListIntoDB(List<GraphData> PointsAndCycles) ;
}
   public void SavePointsAndCyclesListIntoDB(List<GraphData> PointsAndCycles)
    {
        using (SqlConnection dbConnection = new SqlConnection(sqlConection))
        {
            try
我得到一个错误:

 System.Collections.Generic.List<A_Dev_.Analysis.FormA_DataType.GraphData>' to 'System.Collections.Generic.List<A_Dev_.Database.ClassDatabase.GraphData>'

这有几个问题,第一个是函数调用的形式

如果这是唯一的问题你可以这么做

public void button1_Click(object sender, EventArgs e)
{
    Database.SavePointsAndCyclesListIntoDB(PointsAndCycles) ;
}
您在函数调用中声明了一个类型


另一个问题是
PointsAndCycles
似乎不属于当前范围,除非它包含在包含函数的类中。您需要找到一种方法来访问事件处理程序中的
列表
,可能是通过
e
sender
访问,具体取决于您所做的操作。

嘿,我刚刚添加了这个尝试。它不起作用。我以公众身份传递“点和周期”。我尝试了两种方法。第一个参数为“public List PointsAndCycles=new List();”错误-错误CS1503参数1:无法从“System.Collections.Generic.List”转换为“System.Collections.Generic.List”;;如果我尝试公共列表点和循环{get;set;},我会得到相同的错误。事件处理程序和列表在同一个类中吗?是的,两者的形式相同。另一种形式是savepoints和cycleslistinodb;
public List<GraphData> PointsAndCycles = new List<GraphData>();
public struct GraphData
{
    public double Temp1;
    public double Temp2;
    public DateTime Date;
    public string Type;
}
public void button1_Click(object sender, EventArgs e)
{
    Database.SavePointsAndCyclesListIntoDB(PointsAndCycles) ;
}