⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 5.1.txt

📁 《Microsoft Visual C# .NET 2003开发技巧大全》源代码
💻 TXT
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -