• LINQ学习笔记


     int[] numbers = new int[] { 10, 55, 43, 13, 57, 40, 22, 88 };

    var result =
                    from number in numbers
                    where number % 2 == 0
                    orderby number descending
                    select number
    ;

                foreach (var item in result)
                {
                    Console.Write("{0}\t", item);
                }

    ------------------------------------------------------------------------

    string[] words = { "hello", "wonderful", "linq", "beautiful", "world" };

                var groups =
                    from word in words
                    orderby word ascending
                    group word by word.Length into lengthGroup
                    orderby lengthGroup.Key descending
                    select new { Length = lengthGroup.Key, Words = lengthGroup };

                foreach (var group in groups)
                {
                    Console.WriteLine("Words of length " + group.Length);
                    foreach (string word in group.Words)
                        Console.WriteLine(" " + word);
                }

    ------------------------------------------------------------------------

    string[] words = { "hello", "wonderful", "linq", "beautiful", "world" };

                var shortWords =
                    from word in words
                    where word.Length <= 5
                    select word;

                foreach (var word in shortWords)
                    Console.WriteLine(word);

    ------------------------------------------------------------------------

    DataContext dataContext = new DataContext(@"Data Source=......");
                Table<T_IC_APP> appsTable = dataContext.GetTable<T_IC_APP>();

                var apps =
                    from app in appsTable
                    where app.APP_NAME.Contains("FF")
                    select app;

                Console.WriteLine(dataContext.GetCommand(apps).CommandText);

                foreach (var item in apps)
                {
                    Console.WriteLine("APP_ID: {0}, APP_NAME: {1}, APP_DESC: {2}",
                        item.APP_ID, item.APP_NAME, item.APP_DESC);
                }

    [Table(Name = "T_IC_APP")]
            public class T_IC_APP
            {
                [Column(IsPrimaryKey = true, Name = "APP_ID")]
                public string APP_ID { get; set; }

                [Column(Name = "APP_NAME")]
                public string APP_NAME { get; set; }

                [Column(Name = "APP_DESC")]
                public string APP_DESC { get; set; }
            }

    ------------------------------------------------------------------------

     Book[] books = new Book[]
                {
                    new Book("Ajax in Action", "Manning", 2005),
                    new Book("Windows Forms in Action", "Manning", 2006),
                    new Book("RSS and Atom in Action", "Manning", 2006)
                };

                XElement xml = new XElement("books",
                    from book in books
                    where book.Year == 2006
                    select new XElement("book",
                        new XAttribute("title", book.Title),
                        new XElement("publisher", book.Publisher)
                        )

                );

                Console.WriteLine(xml);
            }

        class Book
        {
            public string Publisher;
            public string Title;
            public int Year;

            public Book(string title, string publisher, int year)
            {
                Title = title;
                Publisher = publisher;
                Year = year;
            }
        }

  • 相关阅读:
    关于Git学习-远程库(github) 命令
    关于git的学习
    python-自动化测试结果发送邮件报错(smtplib.SMTPDataError: (554, b'DT:SPM 163……)解决方法
    android SDK- 使用 AVD Manager.exe 创建虚拟机遇到报错 emulator
    性能测试方案大纲-学习笔记
    python + locust 记录一次性能测试的实施
    jmeter 做压测常见问题记录-单台测试机建议最大线程数
    jmeter 调用mysql数据库,使用JDBC请求执行相关SQL
    加解密原理
    SM1,SM2,SM3,SM4刨析
  • 原文地址:https://www.cnblogs.com/RobotTech/p/1914014.html
Copyright © 2020-2023  润新知