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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值