将片段从C转换为C#

时间:2010-08-06 09:21:44

标签: c# c migration

如何将以下代码转换为C#。我的C有点生疏:

short CalcCrc(char *str,int len)
{
  short crc=0;
  for(int i=0;i<len;i++)
    crc ^= (short)((unsigned char)str[i]) << (i%9);
  return crc;
}

1 个答案:

答案 0 :(得分:2)

    short CalcCrc(string str)
    {
        short crc = 0;
        for (int i = 0; i < str.Length; i++)
            crc ^= (short)(str[i] << (i % 9));
        return crc;
    }