zoukankan      html  css  js  c++  java
  • LINQ的一些技巧 (转)

    1.数组初始化

    大小为10的数组,每个元素值都是-1
    int[] a = Enumerable.Repeat(-1, 10).ToArray();

    大小为10的数组,从0至9递增

    int[] b = Enumerable.Range(0, 10).ToArray();

    大小为10的数组,从100,110,120,...,190

    int[] c = Enumerable.Range(0, 10).Select(i => 100 + 10 * i).ToArray();

    2.生成随机数序列

    生成10个范围在10-100的随机数

    Random rand = new Random();
    int [] randomSeq= randomSeq = Enumerable.Repeat(0, 10).Select(i => rand.Next(10,100)).ToArray();

    3.集合类型转换

    int集合转成string集合

    List<int> intList = new List<int> { 1, 2, 3, 4, 5, 5 };
    List<string> strList = new List<string>(intList.Cast<string>());

    反过来,把string集合转成int集合

    List<int> a = strList.Select(o => int.Parse(o)).ToList();

    4.数组倒序

    int [] arr = { 1, 2, 3, 4, 5};
    arr.Reverse();

    现在arr的元素已经是5,4,3,2,1了

  • 相关阅读:
    ant+jenkins+jmeter接口自动化
    fiddler过滤指定的请求
    手机测试
    powerdesign和mysql连接
    testlink安装
    兼容性测试
    sqlserver的事务
    sqlserver中的锁-01
    sqlserve复制
    alwayson10-创建alwayson高可用性组侦听器
  • 原文地址:https://www.cnblogs.com/luluping/p/1215579.html
Copyright © 2011-2022 走看看