77 lines
1.5 KiB
C#
77 lines
1.5 KiB
C#
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);
|
|
}
|
|
|
|
[Test]
|
|
public void Method1()
|
|
{
|
|
var s = Guid.NewGuid().ToString();
|
|
Console.WriteLine(s);
|
|
|
|
var guid = Guid.Parse("9b7cbd24-cf3d-4944-ab5b-9cf5278a5921");
|
|
Console.WriteLine(guid);
|
|
}
|
|
|
|
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);
|
|
} |