zoukankan      html  css  js  c++  java
  • 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";
                }
            }
        }
    }
    

      

  • 相关阅读:
    node介绍和环境安装
    有些运算
    时间与日期
    ISE综合工具XST综合约束相关
    Quartus和ISErom文件格式
    IC设计流程及工具
    PAD PIN
    SQL SERVER 2008 利用发布订阅方式实现数据库同步
    .NET中,写一个函数找出一个整数数组中,第二大的数(整数数组作为函数参数)
    网络嵌入式设备
  • 原文地址:https://www.cnblogs.com/gygtech/p/14322751.html
Copyright © 2011-2022 走看看