111
This commit is contained in:
11
cs5/5_7/5_7.csproj
Normal file
11
cs5/5_7/5_7.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>_5_7</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
25
cs5/5_7/5_7.sln
Normal file
25
cs5/5_7/5_7.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.14.36616.10 d17.14
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "5_7", "5_7.csproj", "{096FB123-18B3-4727-A914-48480106C798}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{096FB123-18B3-4727-A914-48480106C798}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{096FB123-18B3-4727-A914-48480106C798}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{096FB123-18B3-4727-A914-48480106C798}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{096FB123-18B3-4727-A914-48480106C798}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {02E74EAC-8A72-404C-B90C-C6C9BFD815B0}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
53
cs5/5_7/Program.cs
Normal file
53
cs5/5_7/Program.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
namespace _5_7
|
||||
{
|
||||
public class NameListEventArgs : EventArgs
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Count { get; set; }
|
||||
public NameListEventArgs(string name, int count)
|
||||
{
|
||||
Name = name;
|
||||
Count = count;
|
||||
}
|
||||
}
|
||||
public delegate void NameListEventHandler(object source, NameListEventArgs e);
|
||||
public class NameList
|
||||
{
|
||||
ArrayList list;
|
||||
public event NameListEventHandler nameListEvent;
|
||||
public NameList()
|
||||
{
|
||||
list = new ArrayList();
|
||||
}
|
||||
public void Add(string name)
|
||||
{
|
||||
list.Add(name);
|
||||
if (nameListEvent != null)
|
||||
{
|
||||
nameListEvent(this, new NameListEventArgs(name, list.Count));
|
||||
}
|
||||
}
|
||||
}
|
||||
public class EventDemo
|
||||
{
|
||||
public static void Method1(object source, NameListEventArgs e)
|
||||
{
|
||||
Console.WriteLine("增加项目 {0}", e.Name);
|
||||
}
|
||||
public static void Method2(object source, NameListEventArgs e)
|
||||
{
|
||||
Console.WriteLine("当前项目总数 {0}", e.Count);
|
||||
}
|
||||
public static void Main()
|
||||
{
|
||||
NameList myList = new NameList();
|
||||
myList.nameListEvent += new NameListEventHandler(Method1);
|
||||
myList.nameListEvent += new NameListEventHandler(Method2);
|
||||
myList.Add("张三");
|
||||
myList.Add("李四");
|
||||
myList.Add("王五");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user