• CSharp7.0 / C#7.0新语法【部分】


    using System;
    
    namespace CSharp7._0
    {
        class OutClass
        {
            public static void OutTest1(out string param)
            {
                param = "参数";
            }
        }
    
        class BaseInfo
        {
            public BaseInfo(string param1, out string param2)
            {
                param2 = param1;
            }
        }
    
        class SubInfo : BaseInfo
        {
            public SubInfo(string param1) : base(param1, out string param2)
            {
                Console.WriteLine(param2);
            }
        }
    }
    

      

    using System;
    
    namespace CSharp7._0
    {
        class Point
        {
            public Point(string x, string y) => (X, Y) = (x, y);
            public string X { get; set; }
            public string Y { get; set; }
            public void OutPut1(out string x, out string y) => (x, y) = (X, Y);
    
            public static (int i, int j) Rang()
            {
                return (1, 2);
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                //out关键字
                OutClass.OutTest1(out string param);
                Console.WriteLine(param);
    
                SubInfo subInfo = new SubInfo("a1");
    
    
                //元组
                (string param1, string param2) paramAll = ("p1", "p2");
                Console.WriteLine(paramAll.param1);
    
                var pAll = (p1: "12", p2: 13);
                Console.WriteLine(pAll.p2);
    
                var p = (1, "2");
                Console.WriteLine(p.Item1);
    
                Point point = new Point("1", "2");
    
                point.OutPut1(out string x, out string y);
                Console.WriteLine(x);
    
                (int i, int j) = Point.Rang();
                Console.WriteLine(i);
    
    
                //ref局部变量和返回结果
                string s = null;
                RefTest1(ref s);
                Console.WriteLine(s);
    
                //本地函数
               Console.WriteLine(BdFun("张三"));
    
                //增强泛型约束 见其他笔记
            }
    
            static void RefTest1(ref string s)
            {
                if (string.IsNullOrEmpty(s))
                {
                    s = "ref参数";
                }
            }
    
            static string BdFun(string name)
            {
                return Ben(name);
                string Ben(string name)
                {
                    return name + "1";
                }
            }
        }
    }
    

      

  • 相关阅读:
    Golang 学习之路
    Kubernetes 资源对象之DaemonSet
    Spring Cloud服务注册中心交付至kubernetes
    自动化运维之Ansible入门
    MySQL 高可用之主从复制
    Kubernetes 强大的namespace
    SaltStack RESTful API操作
    Kubernetes 服务自动发现CoreDNS
    2个月……
    一次游玩与这两周的一些感想
  • 原文地址:https://www.cnblogs.com/gygtech/p/14322751.html
Copyright © 2020-2023  润新知