Thursday, August 16, 2012

KeyValue pair/Dictionary with duplicate keys

Very recently for my development purpose I need to use Dictionary. And it works very nicely. But problem occurred when requirement changes and face a scenario that duplicate key's are needed to handle in Dictionary which is not possible. So I had written a custom class to handle this problem,please suggests me if there is any better idea.

Examble:

public class KeyValuePair
{
public string Key { get; set; }
public int Value { get; set; }
public string HdValue { get; set; }

public KeyValuePair(string key, int value, string hdValue)
{
this.Key = key;
this.Value = value;
this.HdValue = hdValue;
}
}

Insert Data:
List<KeyValuePair> listKeyValuePair= new List<KeyValuePair>();
listKeyValuePair.Add(new KeyValuePair("TAX",2,"Income Tax"));
listKeyValuePair.Add(new KeyValuePair("TAX",4,"Vatlue added Tax"));
listKeyValuePair.Add(new KeyValuePair("PORT",9,"Vehicle Test"));


Sort Data:
List<KeyValuePair> listSorted = listKeyValuePair.OrderByDescending(x => x.key).ToList();


Filter Data:
var filteredData = listKeyValuePair.where(keyValue=> string.Compare(keyVaue.Key,"TAX")==0).ToList();
if(filteredData.Count > 0)
{
//Do something
}

No comments:

Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'

Exception: Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'...