Get your grouped values organized in a class structure like @Skydiver demonstrated in post 12. Keep it simple and object oriented.Dear All,
I want to create a dictionary whose key is string and values are string and list of six variables.
How can I do this in c#?
class DictionaryData
{
public string Groupnme {get;set;}
public int TableID{get;set;}
public List<OutputData> _EMS_OutputDatas = new List<OutputData>
}
class OutputData
{
public string Dispname {get;set;}
public string Lablename {get;set;}
public object unit {get;set;}
}
public List<OutputData>calculate(string DI){
List<OutputData> OutputData_obj = new List<OutputData>();
List<string>ruledata = new List<string>();
for(i=0;i<ruledata.count();i++)
{
OutputData obj =new OutputData();
obj.DisplayName=ruledata[i].Displayname;
obj.Labelname = ruledata[i].lablename;
obj.unit=ruledata[i].k;
OutputData_obj.Add(obj);
}
return OutputData_obj;
}
void main()
{
Dictionary<string,DictionaryData> kvp = new Dictionary<string,DictionaryData>();
DictionaryData mydict = new DictionaryData();
List<string> mylist = new List<string>();
for(i=0;i<mylist.count;i++)
{
mydict.Groupnme = GetGroupname();
mydict.TableID= GetTableID();
mydict._EMS_OutputDatas=calculate(mylist[i]);
kvp.Add(mylist[i],mydict);
}
}
mydict
that you instantiated on line 31. C# (like Java) passes objects by reference, not by value (like C and C++).kvp
are referring to the same object.mylist.count
. Note that "count" with a lower case 'c' is not a field of a List<T>
.void main()
. Note that this should be static void Main()
.kvp
because mylist
will be empty, and therefore the for loop on line 33 will never be entered.calculate()
returns a new list. Unfortunately, the way it is currently written in post #17, it won't compile. And even if it compiled, it will return an empty list because the for loop will never be entered.list<T> CreateList()
let l be a new instance of list<t>
populate l with instances of t
return l
Why not? Is it a top secret military government project funded on a black budget?I can't share the real code