将代码从C转换为C# [英] Translating code from C to C#

查看:115
本文介绍了将代码从C转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将C代码修改为C#,而我被困在这里:

Im trying to modify a C code into C# and Im stuck here:

typedef struct { char index; char f; char g; char k; } todo;

static const todo for4[] = {
  {0,2,15,4} , {0,3,5,1} , {0,3,25,11} , {0,5,9,3}
, {0,5,21,9} , {0,7,15,7} , {0,8,15,8} , {0,10,9,8}
, {0,10,21,14} , {0,12,5,10} , {0,12,25,20} , {0,13,15,15}
, {0,15,1,15} , {0,15,11,17} , {0,15,19,21} , {0,15,29,29}
, {3,1,3,0} , {3,1,27,12} , {3,4,3,1} , {3,4,27,13}
, {3,6,7,3} , {3,6,13,5} , {3,6,17,7} , {3,6,23,11}
, {3,9,7,6} , {3,9,13,8} , {3,9,17,10} , {3,9,23,14}
, {3,11,3,8} , {3,11,27,20} , {3,14,3,13} , {3,14,27,25}
, {4,2,1,0} , {4,2,11,2} , {4,2,19,6} , {4,2,29,14}
, {4,7,1,3} , {4,7,11,5} , {4,7,19,9} , {4,7,29,17}
, {4,8,1,4} , {4,8,11,6} , {4,8,19,10} , {4,8,29,18}
, {4,13,1,11} , {4,13,11,13} , {4,13,19,17} , {4,13,29,25}
, {7,1,5,0} , {7,1,25,10} , {7,4,5,1} , {7,4,25,11}
, {7,5,7,2} , {7,5,13,4} , {7,5,17,6} , {7,5,23,10}
, {7,10,7,7} , {7,10,13,9} , {7,10,17,11} , {7,10,23,15}
, {7,11,5,8} , {7,11,25,18} , {7,14,5,13} , {7,14,25,23}
, {9,2,9,1} , {9,2,21,7} , {9,3,1,0} , {9,3,11,2}
, {9,3,19,6} , {9,3,29,14} , {9,7,9,4} , {9,7,21,10}
, {9,8,9,5} , {9,8,21,11} , {9,12,1,9} , {9,12,11,11}
, {9,12,19,15} , {9,12,29,23} , {9,13,9,12} , {9,13,21,18}
, {10,2,5,0} , {10,2,25,10} , {10,5,1,1} , {10,5,11,3}
, {10,5,19,7} , {10,5,29,15} , {10,7,5,3} , {10,7,25,13}
, {10,8,5,4} , {10,8,25,14} , {10,10,1,6} , {10,10,11,8}
, {10,10,19,12} , {10,10,29,20} , {10,13,5,11} , {10,13,25,21}
, {13,1,15,3} , {13,4,15,4} , {13,5,3,1} , {13,5,27,13}
, {13,6,5,2} , {13,6,25,12} , {13,9,5,5} , {13,9,25,15}
, {13,10,3,6} , {13,10,27,18} , {13,11,15,11} , {13,14,15,16}
, {13,15,7,15} , {13,15,13,17} , {13,15,17,19} , {13,15,23,23}
, {14,1,7,0} , {14,1,13,2} , {14,1,17,4} , {14,1,23,8}
, {14,4,7,1} , {14,4,13,3} , {14,4,17,5} , {14,4,23,9}
, {14,11,7,8} , {14,11,13,10} , {14,11,17,12} , {14,11,23,16}
, {14,14,7,13} , {14,14,13,15} , {14,14,17,17} , {14,14,23,21}
} ;



它看起来像一个委托函数,但是我不确定如何将代码转换为C#.我已阅读以下内容:
http://msdn.microsoft.com/en-us/library/05w82thz%28v = vs.71%29.aspx [ ^ ]

但是仍然无法用C#来解决问题.


顺便说一句:有几个模拟表以及其他大小合适的数组,它们分别为:



It looks like a delegate function of sort but Im not sure how I could translate the code into C#. I have read this:
http://msdn.microsoft.com/en-us/library/05w82thz%28v=vs.71%29.aspx[^]

But still cant wrap my head around how to do it in C#.


BTW: There are several simular tables with other eaqualy sized arrays named:

static const todo for6[] = {...
static const todo for12[] = {...

推荐答案

此代码应使您朝正确的方向前进:

This code should get you going in the right direction :

public class todo
    {
        public char index;
        public char f;
        public char g;
        public char k;
    }

    public class A{
        static readonly todo[] for4 = 
          new todo[]{new todo(){index='a',f='a',g='a',k='a'},
                                                 
                     new todo(){index = (char)1,f='a',g='a',k='a'}
        };
    }



通过为todo类提供构造函数,一些快捷方式是可能的,因此您不必像在我的示例中那样在其构造中命名每个成员.
我提供了一个(char)1元素来展示如何在代码中使用数字.



Some shortcuts are possible by providing a constructor to the todo class so that you don''t have to name each member in its construction as it is in my example.
I provided one element as (char)1 to show how to use numbers like in your code.


这篇关于将代码从C转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆