加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

单引号字符串到uint在c#

发布时间:2020-12-14 01:41:50 所属栏目:Windows 来源:网络整理
导读:参见英文答案 What do single quotes do in C++ when used on multiple characters?4个 Single quotes vs. double quotes in C or C++12个 我正在翻译一些C到C#代码,我看到下面的定义: #define x 'liaM' 首先,这个单引号是什么意思?我在c#中使其成为字符串
参见英文答案 > What do single quotes do in C++ when used on multiple characters?4个
> Single quotes vs. double quotes in C or C++12个
我正在翻译一些C到C#代码,我看到下面的定义:
#define x 'liaM'

首先,这个单引号是什么意思?我在c#中使其成为字符串常量吗?

其次,这个常数被赋值为C中的uint变量.这是如何工作的?

uint m = x;
这有时被称为 FOURCC.有一个Windows API可以将字符串转换为称为 mmioStringToFOURCC的FOURCC,这里有一些C#代码来做同样的事情:
public static int ChunkIdentifierToInt32(string s)
{
    if (s.Length != 4) throw new ArgumentException("Must be a four character string");
    var bytes = Encoding.UTF8.GetBytes(s);
    if (bytes.Length != 4) throw new ArgumentException("Must encode to exactly four bytes");
    return BitConverter.ToInt32(bytes,0);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读