Click here to Skip to main content
15,885,132 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I have a Dictionary object crated for all fields.

Now, i want to compare the field (I am changing the Field value) from the Dictionary.

Below is the code:

DICTIONARY:

C#
Dictionary<string, Dictionary<string, Int32>> ID = new Dictionary<string, Dictionary<string, Int32>>()


GOT ALL FIELDS INTO COLLECTION:

C#
FieldCollection FC=(FieldCollection)this.#######.Fields;

foreach(var item in FC)
{
//How to compare the field from dictionary
}


What I have tried:

I tried googling but unable to get it
Posted
Updated 25-May-16 9:25am
v2
Comments
Sergey Alexandrovich Kryukov 25-May-16 10:23am    
You did not show any types with public fields, so what are you going to compare? With what? You have two string keys and one Int32 value...
—SA
CHill60 25-May-16 10:47am    
You have a "Dictionary of Dictionaries" - did you really mean this?
What is the relevance of ID? It's not populated by anything you have shown us.
What are you trying to compare?
Does the FieldCollection contain fields from SharePoint or TeamFoundation?
You need to give us a lot more information before we can help you

1 solution

I have assumed that getting the dictionary out of the dictionary called ID is what you are after

C#
foreach(KeyValuePair<string,>> pair in ID)
{
  Dictionary<string,int> inner = pair.Value;
  //You can now do what comparisons here you need to do on the dictionary.
}
 
Share this answer
 
v2
Comments
Matt T Heffron 25-May-16 15:28pm    
If just getting the Value of the pair, then:
foreach (var inner in ID.Values)
{
// etc...
}

is much simpler!
Simon_Whale 25-May-16 17:23pm    
Yeah I see that, but I personally am not a fan of the various keyword
Matt T Heffron 25-May-16 17:30pm    
So it becomes:
foreach (Dictionary<string, int> inner in ID.Values)
{
// here inner is the same as your code, but doesn't require dealing with
// KeyValuePair...
// etc...
}

In fact, your code requires creating all of the KeyValuePair instances, while iterating over the ID.Values doesn't need to.
Member 8010354 25-May-16 22:15pm    
Thank you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900