• CSharp: Classes, Structures, And Records in c# 10(donet 6)


       #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/

  • 相关阅读:
    iOS:网络检测
    WinJS:设置listView垂直滚动
    iOS:在AppDelegate中定义managed object context
    简笔画项目总结: ios绘图机制 & 实现记录笔迹功能
    CSS基础
    DOM小结
    iOS:view.frame
    WP:初探
    iOS:UIWebView scrollView 的分页滑动问题
    Mono for Android: 利用mono for android开发的第一个程序
  • 原文地址:https://www.cnblogs.com/geovindu/p/16867898.html
Copyright © 2020-2023  润新知