哪种数据类型用于C#中的无符号字符? [英] Which datatype is used for unsigned char in C#?

查看:79
本文介绍了哪种数据类型用于C#中的无符号字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个c ++应用程序.在该应用程序中,函数之一返回 unsigned char 值.我想将该函数转换为C#代码.但是,我对c ++编程没有足够的了解.我想知道将对 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#.

c ++函数看起来像这样

The c++ function is look like this

unsigned char getValue(string s)
{
    //SOME CODE HERE
}

推荐答案

C#中 unsigned char 的等效项是 byte .

byte getValue(string s)
{

}

第二个选项:如果您使用unsigned char作为字符存储,则应使用 char :

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

char getValue(string s)
{

}


您必须记住,C ++平等对待字符和8字节值.因此,例如在C ++中:


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

您必须从上下文中检查 unsigned char 是字符还是数字.通过将字符串作为参数传递,可以猜测,该函数可以处理字符,因此很可能您需要使用 char C#类型.

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.

这篇关于哪种数据类型用于C#中的无符号字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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