111
This commit is contained in:
11
cs5/5_4/5_4.csproj
Normal file
11
cs5/5_4/5_4.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>_5_4</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
25
cs5/5_4/5_4.sln
Normal file
25
cs5/5_4/5_4.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_4", "5_4.csproj", "{43F29EB3-99B5-4064-911E-3B3570272923}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{43F29EB3-99B5-4064-911E-3B3570272923}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{43F29EB3-99B5-4064-911E-3B3570272923}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{43F29EB3-99B5-4064-911E-3B3570272923}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{43F29EB3-99B5-4064-911E-3B3570272923}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {20D2A0A1-A7D4-4CAC-BC03-AACF2D5F63B0}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
60
cs5/5_4/Program.cs
Normal file
60
cs5/5_4/Program.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
namespace _5_4
|
||||
{
|
||||
public abstract class Shape
|
||||
{
|
||||
protected string name;
|
||||
public Shape(string name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
public abstract void Show();
|
||||
public abstract double Area();
|
||||
}
|
||||
public class Rectangle : Shape
|
||||
{
|
||||
protected double width;
|
||||
protected double height;
|
||||
public Rectangle(string name, double width, double height) : base(name)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
public override void Show()
|
||||
{
|
||||
Console.WriteLine("Rectangle: {0} , area :{1}", name, width * height);
|
||||
}
|
||||
public override double Area()
|
||||
{
|
||||
return width * height;
|
||||
}
|
||||
}
|
||||
public class Circle : Shape
|
||||
{
|
||||
protected double radius;
|
||||
public Circle(string name, double radius) : base(name)
|
||||
{
|
||||
this.radius = radius;
|
||||
}
|
||||
public override void Show()
|
||||
{
|
||||
Console.WriteLine("Circle: {0} , area :{1}", name, Math.PI * radius * radius);
|
||||
}
|
||||
public override double Area()
|
||||
{
|
||||
return Math.PI * radius * radius;
|
||||
}
|
||||
}
|
||||
public class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Shape[] s = { new Rectangle("小矩形",1.0,2.0),
|
||||
new Circle("大源",5.0),
|
||||
};
|
||||
foreach (Shape shape in s)
|
||||
{
|
||||
shape.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
cs5/5_5/5_5.csproj
Normal file
11
cs5/5_5/5_5.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>_5_5</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
25
cs5/5_5/5_5.sln
Normal file
25
cs5/5_5/5_5.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_5", "5_5.csproj", "{C2EFCC00-2BDF-4E39-BBF1-FB54B8CB2708}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C2EFCC00-2BDF-4E39-BBF1-FB54B8CB2708}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C2EFCC00-2BDF-4E39-BBF1-FB54B8CB2708}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C2EFCC00-2BDF-4E39-BBF1-FB54B8CB2708}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C2EFCC00-2BDF-4E39-BBF1-FB54B8CB2708}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {987BE462-C992-48BE-98EB-41564DDA8179}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
46
cs5/5_5/Program.cs
Normal file
46
cs5/5_5/Program.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
namespace _5_5
|
||||
{
|
||||
public struct Complex
|
||||
{
|
||||
public int real;
|
||||
public int imag;
|
||||
public Complex(int r, int i)
|
||||
{
|
||||
this.real = r;
|
||||
this.imag = i;
|
||||
}
|
||||
public static Complex operator +(Complex c1, Complex c2)
|
||||
{
|
||||
return new Complex(c1.real + c2.real, c1.imag + c2.imag);
|
||||
}
|
||||
public static Complex operator -(Complex c1, Complex c2)
|
||||
{
|
||||
return new Complex(c1.real - c2.real, c1.imag - c2.imag);
|
||||
}
|
||||
public static Complex operator *(Complex c1, Complex c2)
|
||||
{
|
||||
return new Complex(c1.real * c2.real - c1.imag * c2.imag, c1.real * c2.imag + c1.imag * c2.real);
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return (string.Format("{0}+{1}i", this.real, this.imag));
|
||||
}
|
||||
}
|
||||
public class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Complex c1 = new Complex(2, 3);
|
||||
Complex c2 = new Complex(4, 5);
|
||||
Complex sum = c1 + c2;
|
||||
Complex diff = c1 - c2;
|
||||
Complex prod = c1 * c2;
|
||||
Console.WriteLine("第一个复数" + c1);
|
||||
Console.WriteLine("第二个复数" + c2);
|
||||
Console.WriteLine("复数的和" + sum);
|
||||
Console.WriteLine("复数的差" + diff);
|
||||
Console.WriteLine("复数的积" + prod);
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
cs5/5_6/5_6.csproj
Normal file
11
cs5/5_6/5_6.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>_5_6</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
25
cs5/5_6/5_6.sln
Normal file
25
cs5/5_6/5_6.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_6", "5_6.csproj", "{93E19541-FEF3-4004-878B-615610904002}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{93E19541-FEF3-4004-878B-615610904002}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{93E19541-FEF3-4004-878B-615610904002}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{93E19541-FEF3-4004-878B-615610904002}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{93E19541-FEF3-4004-878B-615610904002}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {49161CD3-DF8F-4571-A2D5-DDDC82BFFCC2}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
61
cs5/5_6/Program.cs
Normal file
61
cs5/5_6/Program.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
namespace _5_6
|
||||
{
|
||||
public interface ICDPlayer
|
||||
{
|
||||
void Play();
|
||||
void Stop();
|
||||
void PreviousTrack();
|
||||
void NextTrack();
|
||||
int CurrentTrack
|
||||
{
|
||||
get;
|
||||
}
|
||||
}
|
||||
public class CDPlayer : ICDPlayer
|
||||
{
|
||||
private int currentTrack = 0;
|
||||
public void Play()
|
||||
{
|
||||
Console.WriteLine("启动CD。。。");
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
Console.WriteLine("停止播放CD。。。");
|
||||
}
|
||||
public void PreviousTrack()
|
||||
{
|
||||
if (currentTrack > 0)
|
||||
{
|
||||
currentTrack--;
|
||||
}
|
||||
Console.WriteLine("上一音轨:");
|
||||
}
|
||||
public void NextTrack()
|
||||
{
|
||||
Console.WriteLine("下一音轨:");
|
||||
currentTrack++;
|
||||
}
|
||||
public int CurrentTrack
|
||||
{
|
||||
get
|
||||
{
|
||||
return currentTrack;
|
||||
}
|
||||
}
|
||||
}
|
||||
public class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
CDPlayer mycd = new CDPlayer();
|
||||
mycd.Play();
|
||||
Console.WriteLine("当前音轨:" + mycd.CurrentTrack);
|
||||
mycd.NextTrack();
|
||||
Console.WriteLine("当前音轨:" + mycd.CurrentTrack);
|
||||
mycd.PreviousTrack();
|
||||
Console.WriteLine("当前音轨:" + mycd.CurrentTrack);
|
||||
mycd.Stop();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
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