帮忙C# 程序改错误。

appletan 2006-04-10 11:51:56
using System;
public class addrsOpr
{
unsafe public static int Main(string[] args)
{
// addrsOpr.cs
// A C# program demonstrating how to use
// the Binary AND operator & to return
// the address of an unsafe value
// PROGRAM DOES NOT COMPILE - erad last comment!!!
// Copyright (c) Chris H. Pappas and William H. Murray, 2001
//

Console.WriteLine("& used on true AND true = {0}", true & true);
Console.WriteLine("& used on true AND false = {0}", true & false);

int iValue = 4;

// the following "fixed" block IS crrect - hower,
// the program will NOT compile - WHY?
fixed(int *pi = &iValue)
{
string hexAddress = int.Format((int)pi, "x");
Console.WriteLine("& returning address of iValue: {0}", hexAddress);

// or the simpler version, not using teh string variable
Console.WriteLine("& returning address of iValue: {0}", int.Format((int)pi, "x"));
}

// to get addrsOpr.cs to compile and execute
// your MUST remember - ANY method using unsafe pointers
// must include the "unsafe" keyword in the method prototype
// when you change Main()'s prototype to:
// unsafe public static int Main(string[] args)
// the program will compile and execute!

return 0;
}
}
...全文
418 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluemoonright 2006-05-24
  • 打赏
  • 举报
回复
fixed(int *pi = &iValue)
{...}
上面这个东东,你能不能告诉我是CLASS还是方法?,除了构造函数,我还没见过这种东西.
xjc1985 2006-05-10
  • 打赏
  • 举报
回复
fixed(int *pi = &iValue)???
cctvnight 2006-05-04
  • 打赏
  • 举报
回复
我觉得函数嵌套由问题

1,978

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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