且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

需要帮助将C ++代码转换为C#

更新时间:2023-02-07 22:59:22

首先,即使是C ++,代码也不太好:
1)使用所有这些立即数(89、27,"1"等)使代码很难维护; 2)与字符"1"进行比较是表示纯逻辑的不好方法,3)未显示一些声明:ais_binary在哪里(可能是某些实现索引的类的实例),temp_s?

缺少一些声明使直译变得不确定,但是您只需要一些想法:

First of all, the code is not so good even as C++:
1) use of all those immediate constants (89, 27, ''1'', etc.) makes the code very hard to maintain; 2) comparison with character ''1'' is bad way to represent pure logic, 3) some declarations are not shown: where is ais_binary (could be an instance of some class implementing indexing), temp_s?

The lack of some declarations makes literal translation uncertain, but you only need some ideas:

  • To represent bit set, use System.Collections.BitArray,
    see http://msdn.microsoft.com/en-us/library/system.collections.bitarray.aspx[^].
  • To get a slice of some array use the static methods <copy>System.Array.Copy. See: http://msdn.microsoft.com/en-us/library/system.array.aspx[^],
    http://msdn.microsoft.com/en-us/library/z50k9bft.aspx[^].
  • Everything else looks the same: if statement, block…