31 lines
761 B
C#
31 lines
761 B
C#
using System.Text.Json;
|
|
|
|
namespace CSharpTest
|
|
{
|
|
public record Person(string name,int age);
|
|
|
|
public class RecordTests
|
|
{
|
|
[SetUp]
|
|
public void Setup() {
|
|
}
|
|
|
|
[Test]
|
|
public void Test1() {
|
|
var p1 = new Person("ÕÅÈý",40);
|
|
var p2 = p1 with { age = 50 };
|
|
Console.WriteLine(p1 == p2);
|
|
Console.WriteLine(p1.Equals(p2));
|
|
|
|
Console.WriteLine(p1.ToString());
|
|
Console.WriteLine(JsonSerializer.Serialize(p1));
|
|
Console.WriteLine(JsonSerializer.Serialize(p2));
|
|
|
|
var p3 = new Person("ÕÅÈý",40);
|
|
var p4 = new Person("ÕÅÈý",40);
|
|
Console.WriteLine(p3 == p4);
|
|
Assert.IsTrue(p3 == p4);
|
|
|
|
}
|
|
}
|
|
} |