在 C# 中,如何将 DWORD 声明为 uint32?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/745425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 23:33:20  来源:igfitidea点击:

In C#, How to declare DWORD as an uint32?

c#

提问by CrashCodes

I guess the question is really about how to define a type as an existing primitive data type. Below clearly doesn't work, but I think you'll get the idea.

我想问题实际上是关于如何将类型定义为现有的原始数据类型。下面显然行不通,但我想你会明白的。

Type DWORD = typeof(UInt32);

private DWORD func1(int x)
{
    return 123;
}

采纳答案by Mehrdad Afshari

There is no typedefin C#. You can't use #definemacros to replace strings either (they are just conditional). The only rough equivalent is using DWORD = System.UInt32;on top of your source file.

typedefC# 中没有。您也不能使用#define宏来替换字符串(它们只是有条件的)。唯一粗略的等效项位于using DWORD = System.UInt32;源文件的顶部。

回答by dommer

What about

关于什么

using DWORD = System.UInt32;

Downside to this is that you'll have to do it in each file that you require it in.

这样做的缺点是您必须在需要它的每个文件中执行此操作。

回答by Steve

I think you are talking about type aliasing, the way to do that in C# is using the usingkeyword.

我认为您在谈论类型别名,在 C# 中这样做的方法是使用using关键字。

e.g.

例如

using DWORD = System.Uint32