• Saves Valuable Time
  • Trusted Accuracy for 12 Years
  • 15-Day Money-Back Guarantee

C# Equivalent to Java TreeMap

The nearly exact C# (or VB) equivalent to Java's TreeMap collection is the .NET System.Collections.Generic.SortedDictionary collection.

Java C#
void TreeMaps()
{
    java.util.TreeMap<String, Integer> map = new java.util.TreeMap<String, Integer>();
    String s = "test";
    map.put(s, 1);
    int i = map.get(s);
    i = map.size();
    boolean b = map.isEmpty();
    map.remove(s);
}
using System.Collections.Generic;

void TreeMaps()
{
    SortedDictionary<string, int?> map = new SortedDictionary<string, int?>();
    string s = "test";
    map[s] = 1;
    int i = map[s].Value;
    i = map.Count;
    bool b = map.Count == 0;
    map.Remove(s);
}


Use Java to C# Converter to convert from Java to C#.     

Additional resource: Java and C# Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.