zoukankan      html  css  js  c++  java
  • Linq使用(3)

             1.     XDocument doc = XDocument.Parse(returnValue.Trim());
                  var cdistinct = doc.Descendants("reportname").Where(p => Convert.ToString(p.Element(x).Value).Trim() != "").Select(p => Convert.ToString(p.Element(x).Value)).Distinct();
                  string[] dataDistinct=new string[cdistinct.Count()];
                   int i=0;
                   foreach (var count1 in cdistinct)
                  {
                      dataDistinct.SetValue(count1, i);
                      i++;
                  }
                   return dataDistinct;

     

                2.  XElement xml = XElement.Load(文件地址名称);  //定义查询方法                                    

                 var query = from c in  xml.DescendantsAndSelf("Customers")

                  select new CustomerInfo                    

                {                        

                   CustomerID = c.Elements("CustomerID").SingleOrDefault().Value,              

                   CompanyName = c.Elements("CompanyName").SingleOrDefault().Value,        

                      ContactName = c.Elements("ContactName").SingleOrDefault().Value,          

                    ContactTitle = c.Elements("ContactTitle").SingleOrDefault().Value,                

                   Address = c.Elements("Address").SingleOrDefault().Value,            

                   City = c.Elements("City").SingleOrDefault().Value,    

                          PostalCode = c.Elements("PostalCode").SingleOrDefault().Value,            

                  Country = c.Elements("Country").SingleOrDefault().Value,                

                  Phone = c.Elements("Phone").SingleOrDefault().Value,      

                        Fax = c.Elements("Fax").SingleOrDefault().Value,          

                    Region = c.Elements("Region").SingleOrDefault().Value != "" ? true : false

                  };         

  • 相关阅读:
    linux配置虚拟主机
    mysql允许远程登录
    php优化
    php socket 函数
    1-- prometheus安装、图形化界面
    Ansible Roles
    Ansible 的 Playbook
    Ansible 变量
    Ansible 模块
    Ansible入门;Ansible ad-hoc; ansible-vault加密工具 ;ansible-console
  • 原文地址:https://www.cnblogs.com/sunrise/p/1614575.html
Copyright © 2011-2022 走看看