5.1.txt

来自「《Microsoft Visual C# .NET 2003开发技巧大全》源代码」· 文本 代码 · 共 39 行

TXT
39
字号
Listing 5.1 Defining Delegates
using System;
namespace _1_Delegates
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
// instantiate delegates
StringPrinterDelegate.PrintString internalPrint =
new StringPrinterDelegate.PrintString
( StringPrinterDelegate.InternalImp );
StringPrinterDelegate.PrintString firstCharPrint =
new StringPrinterDelegate.PrintString( FirstCharPrint );
// get string from user
Console.Write( “Enter a string: “ );
string input = Console.ReadLine();
// call delegates directly
internalPrint( input );
firstCharPrint( input );
// pass delegates as parameter
StringPrinterDelegate.PrintWithDelegate( internalPrint, input );
StringPrinterDelegate.PrintWithDelegate( firstCharPrint, input );
}
// external delegate implementation
static void FirstCharPrint( string s )
{
string[] splitStrings = s.Split( new char[]{‘ ‘} );
foreach( string splitString in splitStrings )
{
Console.Write( “{0}”, splitString[0] );
for( int i = 0; i < splitString.Length; i++ )
Console.Write( “ “ );
}
Console.WriteLine();
}
}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?