C# 从多个列表创建列表?
我不确定我是不是在做这件事。我需要的是在用户创建所有行之后,可以是1,也可以是10。我可以计算出这些线的长度,将出现该线的区域添加到列表中 所以最后你有一个例子C# 从多个列表创建列表?,c#,list,C#,List,我不确定我是不是在做这件事。我需要的是在用户创建所有行之后,可以是1,也可以是10。我可以计算出这些线的长度,将出现该线的区域添加到列表中 所以最后你有一个例子 Length Location 2 1 4 2 3 1 8 1 之后,我将把这些数据添加到oracle服务器上它们各自的列中。名单合适吗?我当前在Zone1和distfinal上出现越界错误。如果我只做一行,那么我会得到一个长度计算,但在Zone1上会出现一个
Length Location
2 1
4 2
3 1
8 1
之后,我将把这些数据添加到oracle服务器上它们各自的列中。名单合适吗?我当前在Zone1和distfinal上出现越界错误。如果我只做一行,那么我会得到一个长度计算,但在Zone1上会出现一个越界错误
List<string> Zone1 = new List<string>();
private Point p1, p2;
List<Point> p1List = new List<Point>();
List<Point> p2List = new List<Point>();
Dictionary<string, int> Void = new Dictionary<string, int>();
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button.Equals(MouseButtons.Left))
{
if (p1.X == 0)
{
p1.X = e.X;
p1.Y = e.Y;
var color = zoneMap1.GetPixel(e.X, e.Y);
if (color == Color.FromArgb(0, 0, 255))
{
//MessageBox.Show("Zone 1");
Zone1.Add("1");
}
else if (color == Color.FromArgb(0, 255, 0))
{
//MessageBox.Show("Zone 2");
Zone1.Add("2");
}
}
else
{
p2.X = e.X;
p2.Y = e.Y;
p1List.Add(p1);
p2List.Add(p2);
Invalidate();
pictureBox1.Refresh();
p1.X = 0;
}
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
using (var p = new Pen(Color.Red, 5))
{
for (int x = 0; x < p1List.Count; x++)
{
e.Graphics.DrawLine(p, p1List[x], p2List[x]);
}
}
}
好吧,学习了元组 这把它修好了
var list = new List<Tuple<string, int>>();
list.Add(new Tuple<string, int>(Zone1[i], distfinal));
var list=newlist();
添加(新元组(Zone1[i],distfinal));
您的错误发生在哪里?除非我的代码错误,否则您是否确定Zone1
的项目数与p1List
的项目数相同。我不确定有没有更好的办法。现在,第一次单击创建了x并添加了创建它的分区。然后,第二次单击创建y和直线。然后是第二个,依此类推。我想先创建一行,然后查看创建它的区域,添加它,然后转到您创建的下一行,但我不知道如何操作。您的代码缺少有关Zone1
和Void
的信息。它是什么类型的?它是如何定义的?我更新了上面的一些内容。只要我每次都在不同的地方排队,看起来一切都正常。但是,如果我在区域1或区域2中放置了两行,那么它会由于键错误而失败。不知道如何修复,以便在每个区域中有多个条目。
var list = new List<Tuple<string, int>>();
list.Add(new Tuple<string, int>(Zone1[i], distfinal));