首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

java to C#解决方案

2013-10-24 
java to C#Protocol localProtocol (Protocol)Class.forName(protocol. + (this.class_name null ?

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;
         } 
java class switch c# map
[解决办法]
C#中有hashtable和dictionary可以用。
http://msdn.microsoft.com/zh-cn/library/system.collections.hashtable(VS.80).aspx

热点排行