我正在将一些C++翻译成C#代码,我看到了以下定义:
#define x 'liaM'
Run Code Online (Sandbox Code Playgroud)
首先,这个单引号是什么意思?我在c#中使它成为一个字符串常量吗?
其次,将此常量作为值分配给C++中的uint变量.这是如何运作的?
uint m = x;
Run Code Online (Sandbox Code Playgroud)
这有时称为FOURCC。有一个名为mmioStringToFOURCC的 Windows API 可以将字符串转换为 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);
}
Run Code Online (Sandbox Code Playgroud)