As in Java if we declare parameterized constructor of a class as:
public KeyCountMap(Class<? extends Map> _mapType)
{
_map = _mapType.newInstance();
}
where _map is defined as:
private Map<T, MutableInt> _map = new LinkedHashMap<T, MutableInt>();
While in C#, we'll use as:
Type
instead of Class<? extends Map>
private Dictionary<T, MutableInt> _map = new Dictionary<T, MutableInt>();
instead of
private Map<T, MutableInt> _map = new LinkedHashMap<T, MutableInt>();
EDIT
The actual Java constructor considered is:
@SuppressWarnings({ "unchecked", "rawtypes" })
public KeyCountMap(Class<? extends Map> _mapType) throws InstantiationException, IllegalAccessException
{
_map = _mapType.newInstance();
}
As there is no method like newInstance()
in C# and I'm not sure about what Activator.CreateInstance()
does exactly.
How will we create new instance of object of class Type
in C# as done while using java?