当前位置: 首页>>代码示例>>C#>>正文


C# List.Where方法代码示例

本文整理汇总了C#中Library.List.Where方法的典型用法代码示例。如果您正苦于以下问题:C# List.Where方法的具体用法?C# List.Where怎么用?C# List.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Library.List的用法示例。


在下文中一共展示了List.Where方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildLeng

 //Load Length
 public Dictionary<string, int> BuildLeng(List<string> list)
 {
     var leng = new Dictionary<string, int>();
     foreach (string key in list.Where(word => word != ""))
     {
         leng[key] = key.Length;
     }
     return leng;
 }
开发者ID:kevinzhang2012,项目名称:C-Sharp-Programs,代码行数:10,代码来源:BackEnd.cs

示例2: BuildOccu

 //Load Occurances
 public Dictionary<string, int> BuildOccu(List<string> list)
 {
     var occu = new Dictionary<string, int>();
     foreach (string key in list.Where(word => word != ""))
     {
         if (occu.ContainsKey(key))
         {
             occu[key]++;
         }
         else
         {
             occu[key] = 1;
         }
     }
     return occu;
 }
开发者ID:kevinzhang2012,项目名称:C-Sharp-Programs,代码行数:17,代码来源:BackEnd.cs

示例3: Authorize

        public static AuthResult Authorize(AuthData data)
        {
            Keys keys = GetKeys();
            if (keys != null && keys.Public.Equals(data.PublicKey))
            {
                var privateKey = keys.Private;
                var hashCheck = General.Sha1Hash(data.Data + privateKey + data.PublicKey);
                if (hashCheck.Equals(data.Hash))
                {
                    var newToken = General.Sha1Hash(privateKey + hashCheck + GetDateTimeFormatted());
                    var computersJsonFile = GetFile("~/App_Data/", "computers.json");
                    var computers = new List<ComputerData>();
                    try
                    {
                        computers = JsonConvert.DeserializeObject<List<ComputerData>>(GetFileContents(computersJsonFile));
                    }
                    catch { }

                    var computerData = new ComputerData()
                    {
                        Name = data.HostName,
                        IpExternal = data.IpExternal,
                        IpInternal = data.IpInternal,
                        LastActive = DateTime.Now,
                        FileUploaded = null,
                        BytesUploaded = 0,
                        Hash = null
                    };
                    computerData.Hash = Transmitter.GetComputerHash(computerData);
                    if (computers.Where(c => c.Hash == computerData.Hash).FirstOrDefault() == null)
                    {
                        computers.Add(computerData);
                    }

                    var computersJson = JsonConvert.SerializeObject(computers);
                    File.WriteAllText(computersJsonFile, computersJson);

                    return new AuthResult()
                    {
                        Token = newToken,
                        IpExternal = data.IpExternal
                    };
                }
            }
            return null;
        }
开发者ID:rasadeyan,项目名称:RestlessHoneySeeker,代码行数:46,代码来源:RhsApi.cs

示例4: UserWithExpiredBooks

 public static List<User> UserWithExpiredBooks(List<User> users)
 {
     return users.Where(user => user.Books != null && user.Books.Count > 0 && user.Books.Exists(BookController.IsExpiredBook)).ToList<User>();
 }
开发者ID:asadmira,项目名称:Library,代码行数:4,代码来源:UserController.cs

示例5: UsersWithBooks

 public static List<User> UsersWithBooks(List<User> users)
 {
     return users.Where(user => user.Books != null && user.Books.Count > 0).ToList<User>();
 }
开发者ID:asadmira,项目名称:Library,代码行数:4,代码来源:UserController.cs

示例6: Update

        public void Update()
        {
            lock (this.ThisLock)
            {
                if (this.State == ManagerState.Stop) return;

                {
                    string ipv4Uri = null;

                    try
                    {
                        string uri = _outoposManager.ListenUris.FirstOrDefault(n => n.StartsWith(string.Format("tcp:{0}:", IPAddress.Any.ToString())));

                        Regex regex = new Regex(@"(.*?):(.*):(\d*)");
                        var match = regex.Match(uri);
                        if (!match.Success) throw new Exception();

                        int port = int.Parse(match.Groups[3].Value);

                        List<IPAddress> myIpAddresses = new List<IPAddress>(AutoBaseNodeSettingManager.GetIpAddresses());

                        foreach (var myIpAddress in myIpAddresses.Where(n => n.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork))
                        {
                            if (IPAddress.Any.ToString() == myIpAddress.ToString()
                                || IPAddress.Loopback.ToString() == myIpAddress.ToString()
                                || IPAddress.Broadcast.ToString() == myIpAddress.ToString())
                            {
                                continue;
                            }
                            if (AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("10.0.0.0")) >= 0
                                && AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("10.255.255.255")) <= 0)
                            {
                                continue;
                            }
                            if (AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("172.16.0.0")) >= 0
                                && AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("172.31.255.255")) <= 0)
                            {
                                continue;
                            }
                            if (AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("127.0.0.0")) >= 0
                                && AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("127.255.255.255")) <= 0)
                            {
                                continue;
                            }
                            if (AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("192.168.0.0")) >= 0
                                && AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("192.168.255.255")) <= 0)
                            {
                                continue;
                            }

                            ipv4Uri = string.Format("tcp:{0}:{1}", myIpAddress.ToString(), port);

                            break;
                        }
                    }
                    catch (Exception)
                    {

                    }

                    if (ipv4Uri != _settings.Ipv4Uri)
                    {
                        if (this.RemoveUri(_settings.Ipv4Uri))
                            Log.Information(string.Format("Remove Node uri: {0}", _settings.Ipv4Uri));
                    }

                    _settings.Ipv4Uri = ipv4Uri;

                    if (_settings.Ipv4Uri != null)
                    {
                        if (this.AddUri(_settings.Ipv4Uri))
                            Log.Information(string.Format("Add Node uri: {0}", _settings.Ipv4Uri));
                    }
                }

                {
                    string ipv6Uri = null;

                    try
                    {
                        string uri = _outoposManager.ListenUris.FirstOrDefault(n => n.StartsWith(string.Format("tcp:[{0}]:", IPAddress.IPv6Any.ToString())));

                        Regex regex = new Regex(@"(.*?):(.*):(\d*)");
                        var match = regex.Match(uri);
                        if (!match.Success) throw new Exception();

                        int port = int.Parse(match.Groups[3].Value);

                        List<IPAddress> myIpAddresses = new List<IPAddress>(AutoBaseNodeSettingManager.GetIpAddresses());

                        foreach (var myIpAddress in myIpAddresses.Where(n => n.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6))
                        {
                            if (IPAddress.IPv6Any.ToString() == myIpAddress.ToString()
                                || IPAddress.IPv6Loopback.ToString() == myIpAddress.ToString()
                                || IPAddress.IPv6None.ToString() == myIpAddress.ToString())
                            {
                                continue;
                            }
                            if (myIpAddress.ToString().StartsWith("fe80:"))
                            {
//.........这里部分代码省略.........
开发者ID:networkelements,项目名称:Outopos,代码行数:101,代码来源:AutoBaseNodeSettingManager.cs

示例7: ExpiredBooks

 public static List<Book> ExpiredBooks(List<Book> books)
 {
     return books.Where(book => IsExpiredBook(book)).ToList<Book>();
 }
开发者ID:asadmira,项目名称:Library,代码行数:4,代码来源:BookController.cs

示例8: GetListView

        private ListView GetListView(string text, bool? isActive, DateTime date)
        {
            ListView lv = new ListView();

            if (NhatKyNguyenLieuBus.GetCount(text, isActive, date) > 0 && HoaDonBus.GetByDate(date) != null)
            {
                List<DTO.NhatKyNguyenLieu> listNLLyThuyet = new List<DTO.NhatKyNguyenLieu>();
                List<DTO.NhatKyNguyenLieu> listNLThucTe = NhatKyNguyenLieuBus.GetList(string.Empty, true, date,
                    string.Empty, string.Empty, 0, 0);
                List<DTO.HoaDon> listHoaDon = HoaDonBus.GetList(string.Empty, 0, 0, date, string.Empty, string.Empty, 0, 0);

                foreach (DTO.NhatKyNguyenLieu data in listNLThucTe)
                {
                    DTO.NhatKyNguyenLieu dataNKNL = new DTO.NhatKyNguyenLieu();

                    dataNKNL.IdNguyenLieu = data.IdNguyenLieu;
                    dataNKNL.SuDung = 0;

                    listNLLyThuyet.Add(dataNKNL);
                }

                foreach (DTO.HoaDon hoaDon in listHoaDon)
                {
                    List<DTO.HoaDonDetail> listHoaDonDetail = HoaDonDetailBus.GetListByIdHoaDon(hoaDon.Id);

                    foreach (DTO.HoaDonDetail data in listHoaDonDetail)
                    {
                        List<DTO.DinhLuong> listDL = DinhLuongBus.GetListByIdSP(data.IdSanPham);

                        foreach (DTO.DinhLuong dataDL in listDL)
                        {
                            listNLLyThuyet.Where(p => p.IdNguyenLieu == dataDL.IdNguyenLieu).FirstOrDefault().SuDung += dataDL.SoLuong * data.SoLuong;
                        }
                    }
                }

                for (int i = 0; i < lvThongTin.Columns.Count; i++)
                {
                    lv.Columns.Add((ColumnHeader)lvThongTin.Columns[i].Clone());
                }

                for (int i = 0; i < listNLThucTe.Count; i++)
                {
                    double lyThuyet = listNLLyThuyet[i].SuDung;
                    double thucTe = listNLThucTe[i].SuDung;
                    double chenhLech = thucTe - lyThuyet;
                    double percentChenhLech = ((thucTe / lyThuyet) - 1) * 100;

                    ListViewItem lvi = new ListViewItem();

                    lvi.Text = (lv.Items.Count + 1).ToString();
                    lvi.SubItems.Add(listNLThucTe[i].NguyenLieu.Ten);
                    lvi.SubItems.Add(listNLThucTe[i].NguyenLieu.DonViTinh);
                    lvi.SubItems.Add(lyThuyet.ToString());
                    lvi.SubItems.Add(thucTe.ToString());
                    lvi.SubItems.Add(chenhLech.ToString());

                    if (double.IsNaN(percentChenhLech))
                    {
                        lvi.SubItems.Add(Constant.NaN);
                    }
                    else if (double.IsInfinity(percentChenhLech))
                    {
                        lvi.SubItems.Add(Constant.INFINITY);
                    }
                    else
                    {
                        lvi.SubItems.Add(percentChenhLech.ToString(Constant.DEFAULT_FORMAT_PERCENT) + Constant.SYMBOL_PERCENT);
                    }

                    lv.Items.Add(lvi);
                }
            }

            return lv;
        }
开发者ID:vuchannguyen,项目名称:lg-py,代码行数:76,代码来源:UcKiemTraChenhLech.cs

示例9: GetItemsByYear

 public List<Item> GetItemsByYear(List<Item> itemList, ushort year)
 {
     return itemList.Where<Item>(x => x.Year == year).ToList<Item>();
 }
开发者ID:CuriousP,项目名称:C-Sharp,代码行数:4,代码来源:Library.cs


注:本文中的Library.List.Where方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。