zoukankan      html  css  js  c++  java
  • C# 4.0的特性 总结

    动态查阅

    C# 4.0 新增 dynamic关键字,提供动态编程(dynamic programming),把既有的静态对象标记为动态对象,类似javascript, Python 或 Ruby。

    dynamic calc = GetCalculator();
    int sum = calc.Add(10, 20);


     具名参数与可选参数public StreamReader OpenFile(
        string path,
        int bufferSize = 1024)
    {
    ...
    }
    调用 OpenFile 时, 顺序可以完全颠倒:

    OpenFile(bufferSize: 4096, path: "foo.txt");


     与 COM 对象交互在 C#中打开一个Word文件:

    static void Main(string[] args) {
        Word.Application wordApplication = new  
           Word.Application() {Visible = true};    
        wordApplication.Documents.Open(@"C:\\plant.docx",  
           ReadOnly: true); 
    }
    在C#中指定Excel的某一格文字:

    excelObj.Cells[5, 5].Value = "This is sample text";


    泛型的协变和逆变C# 4.0 支持协变和逆变,例如在泛型接口可以加上in、out关键字。

      public interface IComparer<in T> 
      { 
        public int Compare(T left, T right); 
      }
     
      public interface IEnumerable<out T> : IEnumerable
      {
        IEnumerator<T> GetEnumerator();
      }

    这里做简单的总结, 当然还有一些,3.0,4.0语法糖有很多, 同时mvc ,sl,wcf 也是.net程序员必备的技能,努力掌握把!

  • 相关阅读:
    [leedcode 82] Remove Duplicates from Sorted List II
    [leedcode 83] Remove Duplicates from Sorted List
    [leedcode 81] Search in Rotated Sorted Array II
    [leedcode 80] Remove Duplicates from Sorted Array II
    [leedcode 79] Word Search
    2018 ICPC青岛-books(思维题)
    CodeForces 15A-Cottage Village(思维题)
    CodeForces 755A-PolandBall and Hypothesis(思维题)
    CodeForces
    UVA11624-Fire!(BFS)
  • 原文地址:https://www.cnblogs.com/softwarelanguagebs/p/2120735.html
Copyright © 2011-2022 走看看