读书人

java to C#解决方案

发布时间: 2013-10-24 18:27:21 作者: rapoo

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

读书人网 >C#

热点推荐