Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello guys, i have the following code:
Java
    private Map map;


public SomeFunction(Map<?,Integer> map, boolean acsending){
            Set mapEntrySet=map.entrySet();
        Entry entry;
}

and i'm trying to convert it to C#, i've read many topics, some suggested that the Map is equal to IDictionary in C#, but what about Set and Entry??

how could i convert it??
thanks :)
Posted
Updated 9-Mar-13 3:39am
v2
Comments
StM0n 10-Mar-13 1:30am    
Mhm... I'm not aware of equivalent methods, but have you take a closer look to 'GetEnumerator'? There are two methods who gives you all Keys or all Values...
Abdullatif M. Abu Al Rub 11-Mar-13 8:04am    
yes, i've just figured out that it's GetEnumerator...
Thanks :)
StM0n 11-Mar-13 11:45am    
Ok ;)

1 solution

Hello Abdullatif

Java Map or C# IDictionary both represents a key value pair collection. In Java Map.entrySet returns the collection of these key value pairs in form of a Set which is collection with no duplicate values. The Key Value pair itself is represented by Entry which is child interface in Map. The equivalent of Map.Entry for IDictionary Interface is DictionaryEntry.

e.g. Enumerate All String values in a Map
Java
for (Map.Entry<string,> entry : mymap.entrySet())
    System.out.println("Value for Key '" + entry.getKey() + "' is " + entry.getValue());


Equivalent code in C# would be
C#
foreach (DictionaryEntry de in myDictionary)
    Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);


regards,
 
Share this answer
 

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