zoukankan      html  css  js  c++  java
  • 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}";
            }
        }
    }
    
  • 相关阅读:
    pycharm 2016.2注册码
    python selenium2
    webdriver.py--解说
    Sahi ---实现 Web 自动化测试
    性能测试
    看云-git类的书籍写作
    IntelliJ IDEA 对于generated source的处理
    各种常用的序列化性能的对比
    rpc框架--grpc-java
    grpc mvn protobuf:compile 过程
  • 原文地址:https://www.cnblogs.com/hellohongfu/p/6730909.html
Copyright © 2011-2022 走看看