Converting C++ to C#?

  • Thread starter Thread starter jason
  • Start date Start date
J

jason

I have a table that was used in C++. How can I convert this to C#?

static uint16 fcsTable[56]={

0x0110, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
};


Thanks,
Jason
 
Just replace the ... with all the numbers.
private static System.UInt16[] fcsTable = new System.UInt16[] {...};
 
static UInt16[] fcsTable = {0x0110, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad,
0x6536, 0x74bf,0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7,
0x643e, 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e,
0xf0b7,0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 0xe70e,
0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, 0x6b46, 0x7acf,
0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9};

Cheers
Daniel
 
Ok thanks Tim.

But I am now having an issue assigning data to the the table.

Here is what I tried.

private static System.UInt16[] fcsTable = new System.UInt16[5];

fcsTable[] = 0x0110;
fcsTable[] = 0x1189;
fcsTable[] = 0x2312;
fcsTable[] = 0x329b;
fcsTable[] = 0x4624;

I get an error "Syntax error, ']' expected".
Any Ideas?

Thanks again,
Jason
 
jason you still have to tell it the index i.e.
fcsTable[0] = 0x0110;
fcsTable[1] = 0x1189;
fcsTable[2] = 0x2312;
fcsTable[3] = 0x329b;
fcsTable[4] = 0x4624;

Cheers
Daniel
 
Sorry Daniel, I did have the index in place and was getting that
error. "Syntax error, ']' expected"

Copy of my code:
private static System.UInt16[] fcsTable = new System.UInt16[5];

fcsTable[0] = 0x0110;
fcsTable[1] = 0x1189;
fcsTable[2] = 0x2312;
fcsTable[3] = 0x329b;
fcsTable[4] = 0x4624;
Is the Private Static causing an issue?

Thanks,
Jason
 
It shouldn't. Which line gives you the error (can you post a complete
reproducible sample)?

Cheers
Daniel
 
If you declared your array in a function then you should omit "private
static":

private void Test()
{
UInt16[] fcsTable = new System.UInt16[5];

fcsTable[0] = 0x0110;
fcsTable[1] = 0x1189;
fcsTable[2] = 0x2312;
fcsTable[3] = 0x329b;
fcsTable[4] = 0x4624;
}

If it was declared outside the function scope (in the class scope) then:

class TestClass
{
...
private static System.UInt16[] fcsTable = new System.UInt16[5];
private void Test()
{
fcsTable[0] = 0x0110;
fcsTable[1] = 0x1189;
fcsTable[2] = 0x2312;
fcsTable[3] = 0x329b;
fcsTable[4] = 0x4624;
}
}


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
Back
Top