#region Record Types Record Class in C# 10 /// <summary> /// Positional parameters syntax /// 位置参数的语法 /// </summary> /// <param name="EmployeeId"></param> /// <param name="FirstName"></param> /// <param name="LastName"></param> public record Employee(string EmployeeId, string FirstName, string LastName); /// <summary> /// Standard property syntax /// 标准属性的语法 /// </summary> public record DuEmployee { public string EmployeeId { get; init; } public string FirstName { get; init; } public string LastName { get; init; } } #endregion #region Record Structures /// <summary> /// Positional parameters syntax /// 位置参数的语法 /// </summary> /// <param name="EmployeeId"></param> /// <param name="FirstName"></param> /// <param name="LastName"></param> public readonly record struct GeovinEmployee(string EmployeeId, string FirstName, string LastName); /// <summary> /// Standard property syntax /// 标准属性的语法 /// </summary> public readonly record struct GeovinDuEmployee { public string EmployeeId { get; init; } public string FirstName { get; init; } public string LastName { get; init; } } #endregion #region Record Class /// <summary> /// Positional parameters syntax /// 位置参数的语法 /// </summary> /// <param name="EmployeeId"></param> /// <param name="FirstName"></param> /// <param name="LastName"></param> public record TuEmployee(string EmployeeId, string FirstName, string LastName) { public string Designation { get; set; } } /// <summary> /// Standard property syntax /// 标准属性的语法 /// </summary> public record TujuEmployee { public string EmployeeId { get; init; } public string FirstName { get; init; } public string LastName { get; init; } public string Designation { get; set; } } #endregion #region The record structs /// <summary> /// Positional parameters syntax /// 位置参数的语法 /// </summary> /// <param name="EmployeeId"></param> /// <param name="FirstName"></param> /// <param name="LastName"></param> /// <param name="Designation"></param> public record struct TujuwenEmployee(string EmployeeId, string FirstName, string LastName, string Designation); /// <summary> /// Standard property syntax /// 标准属性的语法 /// </summary> public record struct LukEmployee { public string EmployeeId { get; init; } public string FirstName { get; init; } public string LastName { get; init; } public string Designation { get; set; } } #endregion
调用:
Employee employee = new("E001", "Geovin", "Du"); Console.WriteLine(employee); DuEmployee duemployee = new DuEmployee() { EmployeeId = "E001", FirstName = "聚文", LastName = "涂" }; Console.WriteLine(duemployee); GeovinEmployee geovinemployee = new("E001", "Geovin", "Du"); Console.WriteLine(geovinemployee); GeovinDuEmployee geovinduemployess = new GeovinDuEmployee() { EmployeeId = "E001", FirstName = "聚文", LastName = "涂" }; Console.WriteLine(geovinduemployess); TuEmployee tuemployee = new("E001", "聚文", "涂") { Designation = "软件工程师" }; Console.WriteLine(tuemployee); TujuEmployee tujuemployee = new TujuEmployee() { EmployeeId = "E001", FirstName = "Geovin", LastName = "Du", Designation = "Software Engineer" }; Console.WriteLine(tujuemployee); TujuwenEmployee tujuwenemployee = new("E001", "Geovin", "Du", "软件工程师"); Console.WriteLine(tujuwenemployee); LukEmployee lukemployee = new LukEmployee { EmployeeId = "E001", FirstName = "聚文", LastName = "涂", Designation = "Software Engineer" }; Console.WriteLine(lukemployee);
输出:
Employee { EmployeeId = E001, FirstName = Geovin, LastName = Du } DuEmployee { EmployeeId = E001, FirstName = 聚文, LastName = 涂 } GeovinEmployee { EmployeeId = E001, FirstName = Geovin, LastName = Du } GeovinDuEmployee { EmployeeId = E001, FirstName = 聚文, LastName = 涂 } TuEmployee { EmployeeId = E001, FirstName = 聚文, LastName = 涂, Designation = 软件工程师 } TujuEmployee { EmployeeId = E001, FirstName = Geovin, LastName = Du, Designation = Software Engineer } TujuwenEmployee { EmployeeId = E001, FirstName = Geovin, LastName = Du, Designation = 软件工程师 } LukEmployee { EmployeeId = E001, FirstName = 聚文, LastName = 涂, Designation = Software Engineer }
https://bulisor.github.io/Experiments/
https://github.com/BabylonJS/Babylon.js
https://github.com/Bulisor/SmarTeam3D/
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/record-structs
https://github.com/falberthen/NET6.Features
https://github.com/mganss/HtmlSanitizer
https://www.c-sharpcorner.com/article/classes-structures-and-records-oh-my/