Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 根据字典计数创建新类对象的数量_C#_.net_Oop_Collections - Fatal编程技术网

C# 根据字典计数创建新类对象的数量

C# 根据字典计数创建新类对象的数量,c#,.net,oop,collections,C#,.net,Oop,Collections,你为什么不把它分配给一个列表呢 SomeCollection collection =new SomeCollection(obj1,obj2,obj3); 数组类型有一个重载 例如 SomeCollection类只接受类自定义格式,所以列表在这种情况下没有用处,我不明白。为什么不发布SomeCollection类的代码呢。您总是可以更改构造函数,而不是传入ClassCustom类型的对象。您不知道字典密钥计数的编号,因此无法以当前的方式初始化SomeCollection。这是一个micros

你为什么不把它分配给一个列表呢

SomeCollection collection =new SomeCollection(obj1,obj2,obj3);
数组类型有一个重载

例如


SomeCollection类只接受类自定义格式,所以列表在这种情况下没有用处,我不明白。为什么不发布SomeCollection类的代码呢。您总是可以更改构造函数,而不是传入ClassCustom类型的对象。您不知道字典密钥计数的编号,因此无法以当前的方式初始化SomeCollection。这是一个microsoft Automation类,我现在无法更改。我以为SomeCollection是你定制的课程。下次,可能会发布您正在使用的实际Microsoft类。无论如何,如果它是某种集合类,那么应该有一个Add或类似的函数。否则,您可能需要查看另一个重载,它接受ClassCustom的集合。你为什么不告诉我你用的是什么收集类。
SomeCollection collection =new SomeCollection(obj1,obj2,obj3);
int proprtyCount = dictionary.Keys.Count;
var classCustomList = new List<ClassCustom>();
foreach (KeyValuePair<object, object> pair in dictionary)
{
     classCustomList.Add(new ClassCustom(pair.Key, pair.Value));
}

SomeCollection collection = new SomeCollection(classCustomList);
int proprtyCount = dictionary.Keys.Count;
var conditions = new PropertyCondition[propertyCount];
int index = 0;
foreach (KeyValuePair<object, object> pair in dictionary)
{
    conditions[i] = new PropertyCondition(pair.Key, pair.Value));
    index++;
}

var conditionEnabledButtons = new AndCondition(conditions);
var conditions = new PropertyCondition[3];
conditions[0] = new PropertyCondition(AutomationElement.IsEnabledProperty, true);
conditions[1] = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button);
var conditionEnabledButtons = new AndCondition(conditions);