zoukankan      html  css  js  c++  java
  • linq to object 未完待续

    1.linq to string

    string s2 = "abc";
    var data2 = s2.Where(x => x.CompareTo('a') > 0).ToList();
    string s3 = "";
    data2.ForEach(a => { s3 += a.ToString(); });

    2. linq to datatable

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApplication8
    {
    public class Student
    {

    public int No { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
    }

    class Program
    {
    static void Main(string[] args)
    {
    //TestDb2Entities1 DbContext = new TestDb2Entities1();

    //var stu = (from s in DbContext.UserInfoSets where s.Id == 1 select s).First();
    //RoleInfoSet r = stu.RoleInfoSets.ToList()[0];
    //DataTable table=new DataTable();
    //var t = from s in table.AsEnumerable() group s by s.Field<Int32>("") into g select g;

    DataTable table = new DataTable();
    table.Columns.Add("Id", typeof(Int32));
    table.Columns.Add("Name", typeof(String));
    table.Columns.Add("Age", typeof(Int32));

    DataRow row = table.NewRow();
    row["Id"] = 1;
    row["Name"] = "1";
    row["Age"] = 10;
    table.Rows.Add(row);

    row = table.NewRow();
    row["Id"] = 2;
    row["Name"] = "2";
    row["Age"] = 2;
    table.Rows.Add(row);


    row = table.NewRow();
    row["Id"] = 1;
    row["Name"] = "3";
    row["Age"] = 3;
    table.Rows.Add(row);

    //var stus = from s in table.AsEnumerable() group s by s.Field<Int32>("Id") into g select
    //new {
    // key=g.Key,value=g
    //}
    //;


    var stus = from s in table.AsEnumerable()
    where s.Field<Int32>("Id") == 1
    group s by s.Field<Int32>("Id")
    into g
    select g;

    var list = stus.ToList();
    var c = list[0].ToList()[1].Field<Int32>("Age");


    Console.ReadKey();

    }
    }
    }

    3.待续

  • 相关阅读:
    js 鼠标事件大全
    ASP.NET 解决重复提交问题
    C# 统计函数运行时间
    DataGrid 、Repeater、DataList、GridView自动编号列
    两种时间格式正则表达式HH:mm 和HH:mm:ss
    SQL Server2008 新语法
    XYTipsWindow 2.8
    MSSQL 清空日志
    SQL 日期格式化大全
    HDOJ 2132
  • 原文地址:https://www.cnblogs.com/kexb/p/4858017.html
Copyright © 2011-2022 走看看