java to C#

wanderingies 2013-10-16 08:43:44

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;
}
...全文
208 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanderingies 2013-10-16
  • 打赏
  • 举报
回复
引用 1 楼 guwei4037 的回复:
C#中有hashtable和dictionary可以用。 http://msdn.microsoft.com/zh-cn/library/system.collections.hashtable(VS.80).aspx

        public static Protocol ParsePro(ref string s)
        {
            Protocol pro;
            switch (s)
            {
                case "PublicChat":
                    pro = (Protocol)new PublicChat();
                    pro.type = 79;
                    pro.size_policy = 1024;
                    pro.prior_policy = 1;
                    return pro;
            }

            return null;
        }
我重写了,但还是有很多重复工作,怎么样简化,用 Hashtable 保存键对值可以,属性呢??

            Hashtable map = new Hashtable();
            map.Add("PublicChat", new PublicChat());
            Protocol pro;

            if (map.Contains("PublicChat"))
            {
                pro = (Protocol)map["PublicChat"];
                pro.type = 79;
                pro.size_policy = 1024;
                pro.prior_policy = 1;
                return pro;
            }
            return null;
全栈极简 2013-10-16
  • 打赏
  • 举报
回复
支持向量机源码,可在 www.csie.ntu.edu.tw/~cjlin/libsvm/ 下载到最新版本,该版本是 2013年4月更新的,3.17 版。压缩包里面有源代码和文档。以下摘自前述网站: Introduction LIBSVM is an integrated software for support vector classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and distribution estimation (one-class SVM). It supports multi-class classification. Since version 2.8, it implements an SMO-type algorithm proposed in this paper: R.-E. Fan, P.-H. Chen, and C.-J. Lin. Working set selection using second order information for training SVM. Journal of Machine Learning Research 6, 1889-1918, 2005. You can also find a pseudo code there. (how to cite LIBSVM) Our goal is to help users from other fields to easily use SVM as a tool. LIBSVM provides a simple interface where users can easily link it with their own programs. Main features of LIBSVM include Different SVM formulations Efficient multi-class classification Cross validation for model selection Probability estimates Various kernels (including precomputed kernel matrix) Weighted SVM for unbalanced data Both C++ and Java sources GUI demonstrating SVM classification and regression Python, R, MATLAB, Perl, Ruby, Weka, Common LISP, CLISP, Haskell, OCaml, LabVIEW, and PHP interfaces. C# .NET code and CUDA extension is available. It's also included in some data mining environments: RapidMiner, PCP, and LIONsolver. Automatic model selection which can generate contour of cross valiation accuracy.

110,530

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧