zoukankan      html  css  js  c++  java
  • LINQ Introduction

    Microsoft is touting LINQ as a ‘‘groundbreaking innovation’’ that promises to ‘‘revolutionize the way
    developers work with data.’’ Like you, I was somewhat skeptical about these promises because similar
    comments have been funneled our way in the past, but these bold declarations would cause even the
    casual developer to stop and take notice.

    LINQ introducts queries(the concept of a query) as a first-class language construct in both C# and Visual
    Basic. No longer do you need to learn multiple technologies to query multiple data sources. It is a single
    query syntax for querying XML,SQL databases, ADO.NET DataSets, and other data sources.
    LINQ simplifies how you will now write queries. If you use C# or Visual Basic, you will be able to start
    writing LINQ queryies immediately because you know most of what you need. LINQ  is a set of features built
    into Visual Studio 2008 that incorporates tremendous query capabilities directly into the language syntax of
    Visual Basic and C#. This provides the benefits of IntelliSense, compile-time type checking, and debugging
    support. How could life get any better?

    LINQ to XML exposes two classes that help HLINQ integrate with XML:

    XElement and XAttribute.

    XElement class represents an XML element and is used in LINQ to XML to create XML element nodes or
    even to filter out the data you really care about.
    XAttribute class is a name/value pair associated with an XML element. Each XElement contains a list
    of attributes for that element, and the XAttribute class represents an XML attribute.

            static void Main(string[] args)
            {
    
                var xml = new XElement("Objects",
                        new XElement("Obj", "吴xx",new XAttribute("id","1"),new XAttribute("name","wcg") ),
                        new XElement("Obj", "啊xx")
                    );
                Console.WriteLine( xml.ToString() );
                string[] firstnames = { "Scott", "Steve", "Ken", "Joe", "John",
                                          "Alex", "Chuck", "Sarah" };
                var r = new XElement( "Friends",
                            from fn in firstnames
                            where fn.StartsWith("S")
                            select new XElement("Name", fn) );
    
                Console.WriteLine( r.ToString() );
                
                //DirectoryInfo disc=new DirectoryInfo("E:\\");
                //var directories = from dir in disc.GetDirectories()
                //              orderby dir.Name descending
                //              select new { dir.Name };
    
                //foreach (var item in directories)
                //{
                //    Console.WriteLine(item.Name);
                //}
                //-----------------------------------------------------
                //var procs = from proc in Process.GetProcesses()
                //            orderby proc.WorkingSet64 descending
                //            select new { proc.Id, proc.ProcessName, proc.WorkingSet64 };
                //foreach (var item in procs)
                //{
                //    Console.WriteLine("PID={0},PName={1},PMemoryAmount={2}",item.Id,item.ProcessName,item.WorkingSet64);
                //}
                //-----------------------------------------------------
    
    
                Console.ReadKey();
            }
    
  • 相关阅读:
    数据结构--链表基础练习题
    LeetCode 10.28每日一题1207. 独一无二的出现次数【简单】
    数据结构--链表
    LeetCode 10.25每日一题845. 数组中的最长山脉【中等】
    LeetCode 10.22每日一题763. 划分字母区间【中等】
    解决map热点与uni-app中map标签冲突的问题。(Vue Render函数应用)
    【Codeforces 1329A】Dreamoon Likes Coloring
    【Codeforces Alpha Round #20 C】Dijkstra?
    【 Educational Codeforces Round 93 (Rated for Div. 2) D】Colored Rectangles
    【Codeforces Round #643 (Div. 2) C】Count Triangles
  • 原文地址:https://www.cnblogs.com/wucg/p/1845193.html
Copyright © 2011-2022 走看看