| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 258 人关注过本帖
标题:[求助]我初学,我的委托不行了,总是报错。是哪里出了问题?
收藏  订阅  推荐  打印
果汁珊瑚
Rank: 1
等级:新手上路
帖子:15
积分:250
注册:2006-8-4
[求助]我初学,我的委托不行了,总是报错。是哪里出了问题?

using System;

namespace Example_3_第六章
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//

// 存储结果的变量
int result;

// 委托的对象
Call objCall;

// Math 类的对象
Math objMath=new Math();

// 实例化委托
objCall=new Call(objMath.Multiply);

// 调用委托
result=objCall(5.3);
System.Console.WriteLine("结果为:{0}",result);
}
}

class Delegates
{
// 委托定义
public delegate int Call(int num1, int num2);

class Math
{
// 乘法方法
public int Multiply(int num1,int num2)
{
return num1*num2;
}

// 除法方法
public int Divide(int num1, int num2)
{
return num1/num2;
}
}
}
}

搜索更多相关主题的帖子: summary  Math  委托  初学  应用程序  
2007-7-9 11:56
wapfish
Rank: 1
等级:新手上路
帖子:3
积分:130
注册:2007-7-6

测试类写错了:

// 存储结果的变量
int result;

// 委托的对象
Delegates.Call objCall;

// Math 类的对象
Delegates.Math objMath=new Delegates.Math();

// 实例化委托
objCall=new Delegates.Call(objMath.Multiply);

// 调用委托
result=objCall(5,3);
System.Console.WriteLine("结果为:{0}",result);
Console.ReadLine();
}

2007-7-9 12:11
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.066512 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved