zoukankan      html  css  js  c++  java
  • c#语言特性6.0

    茴香豆的N种写法

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net.Http;
    using System.Text;
    using System.Threading.Tasks;
    //静态导入(导入单个类的静态方法
    using static System.Math;
    using static System.String;
    namespace Language._6._0
    {
        public class Student
        {
            //只读的属性
            public string FirstName { get; }
            //自动属性初始化表达式
            public string LastName { get; set; } = "";
    
            //Expression-bodied 函数成员
            //字符串内插
            public override string ToString() => $"{FirstName} {LastName}";
    
            public string FullName => $"{FirstName} {LastName}";
    
            public Student(Student other)
            {
                //Null 条件运算符
                this.LastName = other?.LastName;
                //等价于 this.LastName = other == null ? null : other.LastName;
    
                //空合并运算符(??)该运算符左边不为空则返回左边,否则返回右边
                this.LastName = other?.LastName ?? "test";
                Console.WriteLine(this.LastName);
                Console.WriteLine(this.ToString());
                //异常筛选器
                try
                {
                    throw new HttpRequestException("aaaa301");
                }
                catch (System.Net.Http.HttpRequestException e) when (e.Message.Contains("301"))
                {
                    Console.WriteLine("Site Moved");
                }
    
                //nameof
                Console.WriteLine(nameof(this.FirstName));//FirstName
    
                //使用索引器初始化关联集合
                Dictionary<int, string> webErrors = new Dictionary<int, string>
                {
                    [404] = "Page not Found",
                    [302] = "Page moved, but left a forwarding address.",
                    [500] = "The web server can't come out to play today."
                };
                Console.WriteLine(webErrors[404]);//Page not Found
    
                //
                Task.Run(()=>this.ToString());
    
            }
    
    
            
    
    
        }
    }
    SQL Server
  • 相关阅读:
    模板模式
    简单实用的代理模式
    享元模式
    外观模式(人人都懂的设计模式)
    设计模式之组合模式,温故而知新。
    .net设计模式之装饰模式
    全选、反选
    There is a cycle in the hierarchy解决
    JSONObject、JSONArray
    JsonMessageView工具类
  • 原文地址:https://www.cnblogs.com/zlgan/p/11619710.html
Copyright © 2011-2022 走看看