这是我的班级:
public class ContainerData
{
private List<Dictionary<Contour<Point> , int>> ratioContoursCollection = new List<Dictionary<Contour<Point>,int>>();
public List<Dictionary<Contour<Point>, int>> ratioContoursCollcProperty
{
get { return ratioContoursCollection; }
set { ratioContoursCollection = value; }
}
}
我创建了一个类的实例:
ContainerData _CD = new ContainerData();
我需要在_CD
填充newTriangleRation
和for for循环中的轮廓:
for(i = 0; i < 5; i++)
{
double newTriangleRatio = someFunc();
Contour<Point> contours = someFunc2();
// assignment have to be here!!!
}
知道如何实施它?
答案 0 :(得分:3)
Dictionary<Contour<Point>,int> myDict = new Dictionary<Contour<Point>,int>();
for(i=0;i<5;i++)
{
int newTriangleRatio = someFunc();
Contour<Point> contours = someFunc2();
myDict.Add(contours,newTriangleRatio);
}
_CD.RatioContoursCollcProperty.Add(myDict);
答案 1 :(得分:1)
我猜它可能是这样的:
for(i=0;i<5;i++)
{
double newTriangleRatio = someFunc();
Contour<Point> contours = someFunc2();
Dictionary<Contour<Point>, int> dict = new Dictionary<Contour<Point>, int>();
dict.Add(contours, (int)newTriangleRatio);
_CD.ratioContoursCollcProperty.Add(dict);
}
虽然有5个词典只有一个键,但对我来说没什么意义......