(C#) 将int类型转换为address类型
(C#) Convert int type to address type
我可以编译这样的代码
unsafe static void Main()
{
int i = 5;
int* j = &i;
}
但是如何将地址类型转换为 int 类型,反之亦然?喜欢:
unsafe static void Main()
{
int i = 5;
int _j = (int)&i;
int* j = (AddressType)_j;
}
不知道你想要达到什么目的;您必须先将其转换为 int 才能获得指针。但那是指向指针地址的指针。
enum AddressType
{
a,
b,
c,
d,
e
}
unsafe static void Main()
{
int i = 2;
int _j = (int)&i;
int k = (int)(AddressType)_j;
int* j = &k;
int l = *j;
var s = (int*) l;
int m = *s;
Console.WriteLine(m);
var r = AddressType.b;
AddressType* x = &r;
AddressType y = *x;
Console.WriteLine(y);
}
我可以编译这样的代码
unsafe static void Main()
{
int i = 5;
int* j = &i;
}
但是如何将地址类型转换为 int 类型,反之亦然?喜欢:
unsafe static void Main()
{
int i = 5;
int _j = (int)&i;
int* j = (AddressType)_j;
}
不知道你想要达到什么目的;您必须先将其转换为 int 才能获得指针。但那是指向指针地址的指针。
enum AddressType
{
a,
b,
c,
d,
e
}
unsafe static void Main()
{
int i = 2;
int _j = (int)&i;
int k = (int)(AddressType)_j;
int* j = &k;
int l = *j;
var s = (int*) l;
int m = *s;
Console.WriteLine(m);
var r = AddressType.b;
AddressType* x = &r;
AddressType y = *x;
Console.WriteLine(y);
}