Changing a type within a class when instantiating?

Hey, is it possible to change a specific type to another type when I instantiate a class? Im having trouble wording this, but below is part of the class I wrote. I want to be able to swap out <RegionObject> with a different type, so that this class can be more general and reusable. I feel like thats how Lists<Type> works, but Im unsure where to start googling for this technique.

with the class below, I would like to be able to do something like this: RegionObjectCollection<SomeType> x = new RegionObjectCollection<SomeType>();

and have all the <RegionObject> declarations in the code below become <SomeType> instead.

any help would be much appreciated! even just a link or something, thanks!

public class RegionObjectCollection { private Dictionary<int, Dictionary<int, List<RegionObject>>> _map = new Dictionary<int, Dictionary<int, List<RegionObject>>>(); public void add(RegionId id, RegionObject obj) { int x = id.x; int y = id.y; if (!_map.ContainsKey(x)) { _map.Add(x, new Dictionary<int, List<RegionObject>>()); } if (!_map[x].ContainsKey(y)) { _map[x].Add(y, new List<RegionObject>()); } _map[x][y].Add(obj); } } 

by cmdslssl via /r/csharp

Leave a Reply