Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which datatype is used for unsigned char in C#?

Tags:

c++

c#

I have a c++ application. In that application one of the function is returning unsigned char value. I want to convert that function into C# code. But, I don't have enough knowledge about c++ programming. I want to know what datatype would be placed against c++ unsigned char in C#.

The c++ function is look like this

unsigned char getValue(string s)
{
    //SOME CODE HERE
}
like image 972
Shell Avatar asked Apr 11 '14 06:04

Shell


1 Answers

The equivalent of unsigned char in C# is byte.

byte getValue(string s)
{

}

Second option: if you use unsigned char as a character storage, you should use char:

char getValue(string s)
{

}

You have to remember, that C++ treats characters and 8-byte values equally. So, for instance in C++:

'A' + 'B' == 65 + 66 == 65 + 'B' == 'A' + 66

You have to check from the context, whether the unsigned char is a character or a number. From string being passed as a parameter, one can guess, that the function processes characters so mostly probably you want a char C# type.

like image 128
Spook Avatar answered Sep 28 '22 10:09

Spook