• C#6.0 新功能


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    
    
    
    namespace ConsoleApp2
    {
        class Program
        {
          
            static void Main(string[] args)
            {
    
                Console.WriteLine("输入姓:");
                var lastName = Console.ReadLine();
                Console.WriteLine("输入名:");
    
                var firstName = Console.ReadLine();
                //string format 新写法
                var student = new Student(firstName,lastName);
    
                Console.WriteLine($"student.ToString(){ student.ToString()}");
                Console.WriteLine($"student.FullName{ student.FullName}");
    
                Console.WriteLine("C#6.0新特性");
    
                student = new Student(null,null);
    
    
                Console.WriteLine($"student.ToString(){ student.ToString()}");
                Console.WriteLine($"student.FullName{ student?.FullName}");
                Console.WriteLine($"student.Grades{ student.Grades.Count}");
    
    
    
    
               //异常过滤
                try
                {
                    throw new Exception("测试异常filter");
    
                }
                catch (Exception e) when( e.Message.Contains("filter"))
                {
    
                    Console.WriteLine(e.Message);
                    throw;
                }
                //catch (Exception e) when (e.LogException())
                //{
                //    // This is never reached!
                //}
    
    
                
    
    
                Console.WriteLine("C#6.0新特性");
    
                Console.ReadKey();
    
    
            }
    
            public class Student
            {
                public string LastName {get;}
                public string FirstName { get; }
    
                public Student(string firstName, string lastName)
                {
                    LastName = lastName;
                    FirstName = firstName;
                }
    
                public void SetName(string firstName, string lastName)
                {
                   //this. LastName = lastName;
                   //this.FirstName = firstName;
                }
                //方法表达式
                public ICollection<double> Grades { get; } = new List<double>();
    
                public string GetFormattedGradePoint() =>
    $"Name: {LastName}, {FirstName}. G.P.A: {Grades.Average():F2}";
                public override string ToString() => $"{LastName},{FirstName}";
              
                public string  FullName=>  $"{LastName},{FirstName}";
            }
        }
    }
    
  • 相关阅读:
    Modelsim中观测代码覆盖率
    Allegro中Thermal relief Pad 和Anti Pad
    时序逻辑中阻塞赋值引起的仿真问题
    如何提高FPGA工作频率(转载)
    `include在Verilog中的应用
    forever
    wxpython 应用 使用 google gauth 认证
    sql to sqlalchemy 转换
    django 简易博客开发 5 markdown支持、代码高亮、gravatar头像服务
    simpletodo: 一个简易的 todo 程序 django版
  • 原文地址:https://www.cnblogs.com/hellohongfu/p/6730909.html
Copyright © 2020-2023  润新知