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

  • 相关阅读:
    软件开发(目录规范)
    面向对象编程(UDP协议)
    Django+uwsgi+Nginx
    Django(图书管理系统)
    orm(Manager isn't accessible via %s instances" % cls.__name)报错
    Django(图书管理系统)#转
    docker(mysql-redmine)
    Django(orm)转
    Django(多表查询操作)
    Oracle(ERROR SP2-0642)
  • 原文地址:https://www.cnblogs.com/mikelij/p/1779854.html
Copyright © 2020-2023  润新知