CSharp-Single-EFCore/Bunny.Test.Until/Test/Test1.cs

73 lines
1.3 KiB
C#
Raw Normal View History

using System.Net;
using NUnit.Framework;
namespace Bunny.Test.Until.Test;
public class Animal
{
}
public class Dog : Animal
{
}
public class Test1
{
public int age;
[Test]
public void Start()
{
Animal dog = new Dog();
// 使用委托方式写
Calculate add = (x, y) => x + y;
var result = add(1, 3);
Console.WriteLine(result);
// 使用委托执行函数
MyDelegate myDelegate = Method1;
myDelegate += Method2;
myDelegate += Method3;
myDelegate(); // 调用委托,将依次执行 Method1、Method2 和 Method3
// 多参数传入
TestFun1(1, 2, 3, 4);
var httpClient = new HttpClient();
}
public static implicit operator int(Test1 test1)
{
return 1;
}
public static implicit operator string(Test1 test1)
{
return "Dog";
}
private static void TestFun1(int x, params int[] arg)
{
foreach (var i in arg) Console.WriteLine(i);
}
private static void Method1()
{
Console.WriteLine("Method1");
}
private static void Method2()
{
Console.WriteLine("Method2");
}
private static void Method3()
{
Console.WriteLine("Method3");
}
private delegate void MyDelegate();
private delegate int Calculate(int x, int y);
}