My hashtable contains (key, Values[])
e.g:
myHashtable[keys, Values[]]
myHashtable.Add[1, Value1];
myHashtable.Add[2, Value2];
myHashtable.Add[3, Value3];
myHashtable.Add[4, Value4];
myHashtable.Add[5, Value5];
Where Value1; Value2, value3, value4, and value5 is as follows.
Value1[name = "Smith"]
Value1[Title= "Mr"]
Value1[Salary = 1000]
Value1[Identity = "S"]
Value2[name = "Peter"]
Value2[Title= "Mr"]
Value2[Salary = 1000]
Value2[Identity = "A"]
Value3[name = "Tom"]
Value3[Title= "Mr"]
Value3[Salary = 1000]
Value3[Identity = "C"]
Value4[name = "Marry"]
Value4[Title= "Ms"]
Value4[Salary = 1000]
Value4[Identity = ""]
Value5[name = "Sam"]
Value5[Title= "Mr"]
Value5[Salary = 1000]
Value5[Identity = "C"]
I want to order this dictionaryEntry list values where Identity with "C" values first then "A" then "S" then ""
After sorting the Result should be like as follows.
myHashtable.Add[3, Value3]; // Value3.Identity = "C"
myHashtable.Add[5, Value5]; // Value5.Identity = "C"
myHashtable.Add[2, Value2]; // Value2.Identity = "A"
myHashtable.Add[1, Value1]; // Value1.Identity = "S"
myHashtable.Add[4, Value4]; // Value4.Identity = ""
Here is my attempt.
var result1 = new List<DictionaryEntry>(hashtable.Count);
var result2 = new List<DictionaryEntry>(hashtable.Count);
var result3 = new List<DictionaryEntry>(hashtable.Count);
var result4 = new List<DictionaryEntry>(hashtable.Count);
var result = new List<DictionaryEntry>(hashtable.Count);
foreach (DictionaryEntry entry in hashtable)
{
result.Add(entry);
}
foreach (DictionaryEntry dictionaryEntry in result)
{
var t2 = dictionaryEntry.Value;
switch (t2.Identity)
{
case "C":
result1.Add(dictionaryEntry);
break;
case "A":
result2.Add(dictionaryEntry);
break;
case "S":
result3.Add(dictionaryEntry);
break;
case "":
result4.Add(dictionaryEntry);
break;
default:
break;
}
}
result1.ToList();
result2.ToList();
result3.ToList();
var combinedResult = result1.Union(result2)
.Union(result3)
.Union(result4)
.ToDictionary(k => k.Key, v => v.Value).OrderByDescending(v => v.Value);
How can I sort combinedResult to give me the above custom sorted dictionary entry list?
Any help is greatly appriciated. Thank You