Getting behavior of Java's Class<? extends Map> in .NET

前端 未结 3 2006
一个人的身影
一个人的身影 2021-01-16 21:04

I have a generic class in java defined as:

public static class KeyCountMap 
{
   private Map map = new LinkedHashMap

        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 21:41

    Maybe this is what you want?

    public class KeyCountMap
        where T : new()
    {
        private Dictionary map = new Dictionary();
        // ... rest of properties...  
    
        public KeyCountMap()
        { }
    
        public KeyCountMap(T obj)
        {
            obj = new T();
            map = (Dictionary)(object)obj;
        }
    }
    

提交回复
热议问题