| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 764 人关注过本帖
标题:[求助]我初学,我的委托不行了,总是报错。是哪里出了问题?
只看楼主 加入收藏
果汁珊瑚
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-8-4
收藏
 问题点数:0 回复次数:1 
[求助]我初学,我的委托不行了,总是报错。是哪里出了问题?

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-07-09 11:56
wapfish
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-7-6
收藏
得分:0 

测试类写错了:

// 存储结果的变量
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-07-09 12:11
快速回复:[求助]我初学,我的委托不行了,总是报错。是哪里出了问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011500 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved