程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> 關於.NET >> CLR 4.0有哪些新東西? -- 動態語言支持

CLR 4.0有哪些新東西? -- 動態語言支持

編輯:關於.NET

CLR4.0做了如下改動以支持功能性和動態語言:

大整數BigIntegers

元組Tuples

關於大整數BigIntegers

過去這個表達式 var smallint = unchecked (2000000000 + 2000000000) 會得到-294967296, 現在 CLR4.0為我們准備了System.Numerics.BigIntegers支持更多的位數, 而且所有.net平台的語言都可以使 用.  var bigInt = BigInteger.Add(2000000000 + 2000000000)就可以得到正確得答案.

關於元組Tuples

元組Tuples是一個數學術語, 在這裡指的是一個多維的列表. 它在System名稱空間下. 元組可以有若 干維(似乎維數沒有限制?), 元組的每一維都支持存放范型類型的元素. 訪問每個元素用index索引號就可 以了. 元組的好處是可以快速創建一個結構

使用例子:

var tuple1 = Tuple.Create(4, 'ahmed');
var item1 = tuple1 .Item1;
var item2 = tuple1 .Item2;

將元組作為方法返回:

public static Tuple<bool,int> AddItem(string item)
{
    var result;

    //if item exists in the collection, return A tuple with
    // false, and the index of the existed item in the collection.
    if (collection.Contains(item))
    {
        result = Tuple.Create(false, collection.IndexOf(item));
    }
    // if item doesn't exist in the collection, add the item and return
    // a tuple with true and the index of the inserted item.
    else
    {
        collection.Add(item);
        result = Tuple.Create(true, collection.Count - 1);
    }

    return result;
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved