在C#中如何获取变量的地址的值?如何给变量分配存储空间?请给出方法。

learn2003 2004-01-03 11:27:02
在C#中如何获取变量的地址的值?如何给变量分配存储空间?请给出方法。
...全文
375 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
bankliu 2004-01-04
  • 打赏
  • 举报
回复
unsafe
{
这里面可以使用*i,&i
}
gOODiDEA 2004-01-04
  • 打赏
  • 举报
回复
写托管代码不用你去考虑这些
musicllm 2004-01-04
  • 打赏
  • 举报
回复
用unsafe{
a.ToString()
}不行吗?
FileNewExit 2004-01-03
  • 打赏
  • 举报
回复
If you are intended to get the address of the variable,you may have to resort to unsafe code:

//csc /unsafe GetAddress.cs
using System;

class GetAddress{
unsafe static void Main(){
int i = 10;
Console.WriteLine("The address of {0} is:{1}",i,((int)&i).ToString("X"));
}
}
速马 2004-01-03
  • 打赏
  • 举报
回复
第一个问题做不到
第二个只需要new就行了

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧