2012-09-05 28 views
0

这里创建的实例是我的课:一些重分配类

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(); 

我需要补_CDnewTriangleRation和轮廓在for循环:

for(i = 0; i < 5; i++) 
{ 
    double newTriangleRatio = someFunc(); 
    Contour<Point> contours = someFunc2(); 
    // assignment have to be here!!! 
} 

任何想法我怎么能实现它?

+0

每个'newTriangleRatio'将在一个单独的字典? – Tudor

+0

是的,它将在单独的字典 – Michael

+0

为什么'double',因为你的字典需要'int'作为值? – Tudor

回答

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

我想这可能是这样的:

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个字典只有一个键中的每个没有多大意义的,我......