CLR 4.0有哪些新东西? -- 动态语言支持

简介: CLR4.0做了如下改动以支持功能性和动态语言: 大整数BigIntegers 元组Tuples 关于大整数BigIntegers 过去这个表达式 var smallint = unchecked (2000000000 + 2000000000) 会得到-294967296, 现在CLR4.

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;
}

目录
相关文章
|
XML 开发框架 JSON
成功实现C++调用C#写的库(CLR),我的个人心得与总结
成功实现C++调用C#写的库(CLR),我的个人心得与总结
1592 0
|
10月前
|
开发框架 安全 .NET
【深入理解CLR 五】类型基础
【深入理解CLR 五】类型基础
127 0
|
10月前
|
开发框架 人工智能 自然语言处理
【深入理解CLR 二】CLR的执行模型(下)
【深入理解CLR 二】CLR的执行模型(下)
70 0
|
10月前
|
存储 开发框架 搜索推荐
【深入理解CLR 二】CLR的执行模型(上)
【深入理解CLR 二】CLR的执行模型(上)
110 0
【深入理解CLR 二】CLR的执行模型(上)
|
开发框架 .NET C++
|
.NET Java C#