program.cs
来自「C#高级编程第6版随书源代码 值得下载」· CS 代码 · 共 49 行
CS
49 行
using System;
using System.Collections.Generic;
using System.Text;
namespace MulticastDelegate
{
delegate void DoubleOp(double value);
class MathOperations
{
public static void MultiplyByTwo(double value)
{
double result = value * 2;
Console.WriteLine(
"Multiplying by 2: {0} gives {1}", value, result);
}
public static void Square(double value)
{
double result = value * value;
Console.WriteLine("Squaring: {0} gives {1}", value, result);
}
}
class Program
{
static void ProcessAndDisplayNumber(DoubleOp action, double valueToProcess)
{
Console.WriteLine("\nProcessAndDisplayNumber called with value = " +
valueToProcess);
action(valueToProcess);
}
static void Main()
{
DoubleOp operations = MathOperations.MultiplyByTwo;
operations += MathOperations.Square;
ProcessAndDisplayNumber(operations, 2.0);
ProcessAndDisplayNumber(operations, 7.94);
ProcessAndDisplayNumber(operations, 1.414);
Console.WriteLine();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?