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

C# Equivalent to Java Collection Initializers

Java C#
import java.util.*;

//ArrayList: (Java 9 List.of would also work here)
ArrayList<Integer> myList = new ArrayList<Integer>(Arrays.asList(1, 2, 3));

//HashMap: (Map.ofEntries requires Java 9)
HashMap<String, Integer> myD = new HashMap<String, Integer>(Map.ofEntries(Map.entry(string1, 80), Map.entry(string2, 85)));
//List:
List<int> myList = new List<int>() {1, 2, 3};

//Dictionary:
Dictionary<string, int> myD = new Dictionary<string, int>() {
    {string1, 80},
    {string2, 85}
};


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

Additional resource: Java and C# Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.