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

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

posted on   mikelij  阅读(243)  评论(0编辑  收藏  举报

编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架

导航

< 2009年3月 >
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 1 2 3 4
5 6 7 8 9 10 11
点击右上角即可分享
微信分享提示