日期:2014-05-17  浏览次数:20753 次

java to C#

            Protocol localProtocol = (Protocol)Class.forName("protocol." + (this.class_name == null ? this.name : this.class_name)).newInstance();
            localProtocol.type = Integer.parseInt(this.type);
            localProtocol.size_policy = (this.maxsize == null ? 0 : Integer.parseInt(this.maxsize));
            localProtocol.prior_policy = (this.priority == null ? 0 : Integer.parseInt(this.priority));
            if (this.map.put(this.name.toUpperCase(), localProtocol) != null)
              System.err.println("Duplicate protocol name " + this.name);
            if (this.map.put(this.type, localProtocol) != null)
              System.err.println("Duplicate protocol type " + this.type);



这个是 java 代码在Map里面存入类实例,在C#怎么实现?
我在C#里是这样写的

protected override mars Client(OS os)
         { 

i = os.type();
             switch (i)
             {
                 case 3:
                     return new Class1();
                 case 4:
                     return new Class2();
                 case 5:
                     return new Class3();
                 case 6:
                     return new Class4(); ... ... // 还有很多
             }
             return null;
         }