C# 委托
来源:互联网 发布:人造暖男网络电影 编辑:程序博客网 时间:2024/05/01 07:57
简单的委托示例:
using System;
using System.Collections.Generic;
using System.Text;
namespace DelegateTest
{
class MathsOperation
{
public static double MultiplybyTwo(double value)
{
return value * 2;
}
public static double Square(double value)
{
return value * value;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace DelegateTest
{
delegate double DoubleOp(double x);
class Program
{
static void Main(string[] args)
{
DoubleOp[] operations =
{
new DoubleOp( MathsOperation.MultiplybyTwo ),
new DoubleOp( MathsOperation.Square )
};
for( int i=0;i<operations.Length;i++ )
{
Console.WriteLine( "Using operations[{0}]:",i );
ProcessAndDisplayNumber( operations[i],2.0 );
ProcessAndDisplayNumber( operations[i],7.94 );
ProcessAndDisplayNumber( operations[i],1.414 );
Console.WriteLine();
}
Console.Read();
}
static void ProcessAndDisplayNumber(DoubleOp action, double value)
{
double result = action(value);
Console.WriteLine("Value is {0}, result of operation is {1}", value, result);
}
}
}
- C#委托-委托概述
- C#委托
- C#委托
- C#委托
- c#委托
- C# 委托
- C#委托
- C# 委托
- c#委托
- C#委托
- c#委托
- C#委托
- C# - 委托
- C#委托
- C#委托
- C#委托
- C# 委托
- c#委托
- 炎炎夏日,安全度夏!(图)
- 软件开发者面试百问-----什么是低耦合和高聚合?封装原则又是什么意思?
- ASP.NET自定义控件组件开发 第二章 继承WebControl的自定义控件
- ASP.NET自定义控件组件开发 第三章 为控件添加事件 前篇
- SQL 文 Union 与Order By
- C# 委托
- ASP.NET自定义控件组件开发 第三章 为控件添加事件 后篇
- 中国发展电子商务存在的问题
- ASP.NET自定义控件组件开发 第四章 组合控件开发CompositeControl
- ASP.NET 3.5 Application Architecture and Design
- ASP.NET自定义控件组件开发 第四章 组合控件开发CompositeControl 后篇 --事件冒泡
- Head First C# 中文版 第10章 异常处理 page471
- C++学完了
- 安心做事,减少浮躁,幸福每一天,快乐每一天。