You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
//命名空间同级:调用方只需要引用定义类库就能使用;不需要使用Uing语句引入定义委托的命名空间。
|
|
|
|
|
public delegate string NamespaceLevelDelegate();
|
|
|
|
|
|
|
|
|
|
public delegate string ToLowerDelegate(string source);
|
|
|
|
|
|
|
|
|
|
namespace Study.DelegateSeries.Core
|
|
|
|
|
{
|
|
|
|
|
//类同级:最常用和推荐的,可见范围与使用方法与类相同。
|
|
|
|
|
public delegate string ClassLevelDelegate();
|
|
|
|
|
|
|
|
|
|
public class DeclareDelegateDemo
|
|
|
|
|
{
|
|
|
|
|
//类内部方法同级:可见范围与使用方法与类中方法相似,调用方须先调用类,后再调用委托。
|
|
|
|
|
public delegate string MethodLevelDelegate();
|
|
|
|
|
|
|
|
|
|
public string GetClassName()
|
|
|
|
|
{
|
|
|
|
|
//方法体内:不允许定义委托
|
|
|
|
|
|
|
|
|
|
return "DeclareDelegateDemo";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|