How to Convert Dictionary<String, Object> to ArrayList in C# 3.5 -


i passing dictionary parameter javascript , trying convert array list.

example:

public void assignemployees(dictionary<string, object> _params) {    arraylist arrayex= null;    arrayex= (arraylist)_params["assignments"];     arraylist arrayex1= null;    arrayex1= (arraylist)_params["balance"]; } 

this brief example , have added conditions check if "_params" contains "assignments" or "balance" move forward.

however returns error of unable cast object of type 'system.object[]' type 'system.collections.arraylist'.

here screenshot of ideal data of dictionary object.

enter image description here

you can iterate dictionary , use .add method of arraylist insert object array list. or else try .addrange method linq. following code you:

arraylist arrayex = new arraylist(); foreach (var item in _params) {     arrayex.add(item.value); }  // or  arrayex.addrange(_params.select(x=>x.value).tolist()); 

keep in mind, can use 2 methods instantiated object of arraylist class, don't forget initialize arrayex instance.


Comments