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


C# List.OrderBy方法代码示例

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


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

示例1: AddToMenu

        public static void AddToMenu(Menu menu, List<Spell> spells)
        {
            try
            {
                _menu = menu;

                spells =
                    spells.DistinctBy(s => s.Slot)
                        .Where(s => s.Slot != SpellSlot.Unknown && (s.IsSkillshot || s.Range > 0f))
                        .ToList();

                foreach (var spell in spells)
                {
                    _menu.AddItem(
                        new MenuItem(_menu.Name + "." + spell.Slot, "Use " + spell.Slot).SetValue(
                            spell.Slot != SpellSlot.R && spell.Instance.Cooldown < 20));
                }

                _menu.AddItem(
                    new MenuItem(_menu.Name + ".min-distance", "Min. Enemy Distance").SetValue(
                        new Slider(1000, 200, 3000)));
                _menu.AddItem(new MenuItem(_menu.Name + ".min-mana", "Min. Mana %").SetValue(new Slider(95, 1)));
                _menu.AddItem(new MenuItem(_menu.Name + ".fountain", "Only Inside Fountain").SetValue(false));
                _menu.AddItem(new MenuItem(_menu.Name + ".enabled", "Enabled").SetValue(false));

                _spells = spells.OrderBy(s => s.ManaCost).ThenBy(s => s.Instance.Cooldown).ToList();
                Core.OnPostUpdate += OnCorePostUpdate;
            }
            catch (Exception ex)
            {
                Global.Logger.AddItem(new LogItem(ex));
            }
        }
开发者ID:Lizzaran,项目名称:LeagueSharp-Standalones,代码行数:33,代码来源:TearStackManager.cs

示例2: Index

        public ActionResult Index(int? page, int? PageSize, string sortBy)
        {
            var customers = new List<DSC_CUSTOMER>();
            var viewCustomers = new List<CustViewModel>();
            ViewBag.CurrentItemsPerPage = PageSize ?? 10;
            ViewBag.SortNameParameter = String.IsNullOrEmpty(sortBy) ? "Name desc" : "Name";
            ViewBag.SortParentParameter = sortBy == "Parent" ? "Parent desc" : "Parent"; 

            using (DSC_OBS_DB_ENTITY db = new DSC_OBS_DB_ENTITY())
            {
                customers = db.DSC_CUSTOMER.Where(cust_id => cust_id.dsc_cust_id > 0).ToList();
            }
            //DateTime active_date;
            foreach (DSC_CUSTOMER customer in customers)
            {
                string activeAction = "";
                try
                {
                    if (customer.dsc_cust_eff_end_date == null)
                    {
                        activeAction = "YES";

                    }//end of if
                    else
                    {
                        if (customer.dsc_cust_eff_end_date <= DateTime.Today)
                        {
                            activeAction = "NO";
                        }
                        else
                        {
                            activeAction = "YES";
                        }
                    }//end of else
                }//end of try
                catch
                {
                    activeAction = "NO";
                }//end of catch

                viewCustomers.Add(new CustViewModel(customer.dsc_cust_id, customer.dsc_cust_name, customer.dsc_cust_parent_name, activeAction, activeAction == "YES" ? "Deactivate" : "Activate"));
            }// end of foreach
            switch (sortBy)
            {
                case "Name desc":
                    return View(viewCustomers.OrderByDescending(x=>x.dsc_cust_name).ToPagedList(page ?? 1, PageSize ?? 10));
                case "Parent desc":
                    return View(viewCustomers.OrderByDescending(x => x.dsc_cust_parent_name).ToPagedList(page ?? 1, PageSize ?? 10));
                case"Name":
                    return View(viewCustomers.OrderBy(x => x.dsc_cust_name).ToPagedList(page ?? 1, PageSize ?? 10));
                case "Parent":
                    return View(viewCustomers.OrderBy(x => x.dsc_cust_parent_name).ToPagedList(page ?? 1, PageSize ?? 10));
                default: return View(viewCustomers.ToPagedList(page ?? 1, PageSize ?? 10));


            }

            
            
        }
开发者ID:dsclogistics,项目名称:OBSMVC,代码行数:60,代码来源:CustController.cs

示例3: GetTumblePos

        public static Vector3 GetTumblePos(this Obj_AI_Base target)
        {
            //if the target is not a melee and he's alone he's not really a danger to us, proceed to 1v1 him :^ )
            if (!target.IsMelee && Heroes.Player.CountEnemiesInRange(800) == 1) return Game.CursorPos;

            var aRC = new Geometry.Circle(Heroes.Player.ServerPosition.To2D(), 300).ToPolygon().ToClipperPath();
            var cursorPos = Game.CursorPos;
            var targetPosition = target.ServerPosition;
            var pList = new List<Vector3>();
            var additionalDistance = (0.106 + Game.Ping / 2000f) * target.MoveSpeed;

            if (!cursorPos.IsDangerousPosition()) return cursorPos;

            foreach (var p in aRC)
            {
                var v3 = new Vector2(p.X, p.Y).To3D();

                if (target.IsFacing(Heroes.Player))
                {
                    if (!v3.IsDangerousPosition() && v3.Distance(targetPosition) < 550) pList.Add(v3);
                }
                else
                {
                    if (!v3.IsDangerousPosition() && v3.Distance(targetPosition) < 550 - additionalDistance) pList.Add(v3);
                }
            }
            if (Heroes.Player.UnderTurret() || Heroes.Player.CountEnemiesInRange(800) == 1)
            {
                return pList.Count > 1 ? pList.OrderBy(el => el.Distance(cursorPos)).FirstOrDefault() : Vector3.Zero;
            }
            return pList.Count > 1 ? pList.OrderBy(el => el.Distance(cursorPos)).FirstOrDefault() : Vector3.Zero;
        }
开发者ID:q51251,项目名称:LeagueSharp-1,代码行数:32,代码来源:MyExtensions.cs

示例4: CargaSucursalesNegocio

        private void CargaSucursalesNegocio(int idNegocio)
        {
            try
            {
                List<SucursalNegocio> source = new List<SucursalNegocio>();
                foreach (NegociosEmpresa negocio in _lstNegocios.Where(w => w.IdNegocio == idNegocio))
                {
                    source.AddRange(negocio.SucursalNegocio);
                }
                lvSucursales.Items.Clear();
                ImageList imageList = new ImageList();
                imageList.ImageSize = new Size(64, 64);

                foreach (SucursalNegocio sucursal in source.OrderBy(o => o.Nombre))
                {
                    imageList.Images.Add(Imagenes.ByteToImagen(sucursal.NegociosEmpresa.Logo));
                }
                lvSucursales.View = View.SmallIcon;
                lvSucursales.LargeImageList = imageList;
                lvSucursales.SmallImageList = imageList;
                int count = 0;
                foreach (SucursalNegocio sucursal in source.OrderBy(o => o.Nombre))
                {
                    lvSucursales.Items.Add(sucursal.IdSucursal.ToString(), sucursal.Nombre, count);
                    count++;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
开发者ID:eduardo18razo,项目名称:SmarQuilaChiles,代码行数:32,代码来源:FrmSucursales.cs

示例5: CargarNegocios

        //todo:CAMBIAR ID DE EMPRESA
        private void CargarNegocios(List<NegociosEmpresa> source)
        {
            try
            {
                lvNegocios.Items.Clear();
                ImageList imageList = new ImageList();
                imageList.ImageSize = new Size(64, 64);

                foreach (NegociosEmpresa negocio in source.OrderBy(o => o.Nombre))
                {
                    imageList.Images.Add(Imagenes.ByteToImagen(negocio.Logo));
                }
                lvNegocios.View = View.SmallIcon;
                lvNegocios.LargeImageList = imageList;
                lvNegocios.SmallImageList = imageList;
                int count = 0;
                foreach (NegociosEmpresa negocio in source.OrderBy(o => o.Nombre))
                {
                    lvNegocios.Items.Add(negocio.IdNegocio.ToString(), negocio.Nombre, count);
                    count++;
                }

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
开发者ID:eduardo18razo,项目名称:SmarQuilaChiles,代码行数:29,代码来源:FrmNegocios.cs

示例6: ReloadDataAsync

        public async Task ReloadDataAsync()
        {
            GeoCoordinate coordinates = null;
            List<GeolocalizableModel> result = new List<GeolocalizableModel>();
            await this._gpsProvider.RefreshPositionAsync();

            if(this._gpsProvider.GeolocationAvailable)
            {
                coordinates = this._gpsProvider.GetCurrentPosition;
            }

            foreach (Parking parking in await this._parkingService.RetrieveParkings())
            {
                result.Add(new GeolocalizableModel()
                {
                    Name = parking.Name,
                    Latitude = parking.Latitude,
                    Longitude = parking.Longitude,
                    Distance = coordinates != null ? Distance(coordinates.Latitude, coordinates.Longitude, parking.Latitude, parking.Longitude) : 0d
                });
            }

            if(coordinates == null)
            {
                this.Parkings = new ObservableCollection<GeolocalizableModel>(result.OrderBy(x => x.Name));
            }
            else
            {
                this.Parkings = new ObservableCollection<GeolocalizableModel>(result.OrderBy(x => x.Distance));
            }
        }
开发者ID:mugstrasbourg,项目名称:xamarin-introduction,代码行数:31,代码来源:ParkingViewModel.cs

示例7: DoSearch

        public static List<VendorItem> DoSearch(Mobile m, SearchCriteria criteria)
        {
            if (criteria == null || PlayerVendor.PlayerVendors == null || PlayerVendor.PlayerVendors.Count == 0)
                return null;

            List<VendorItem> list = new List<VendorItem>();
            bool excludefel = criteria.Details.FirstOrDefault(d => d.Attribute is Misc && (Misc)d.Attribute == Misc.ExcludeFel) != null;

            foreach (PlayerVendor pv in PlayerVendor.PlayerVendors.Where(pv => pv.Backpack != null && pv.Backpack.Items.Count > 0 && (!excludefel || pv.Map != Map.Felucca)))
            {
                List<Item> items = GetItems(pv);

                foreach (Item item in items.Where(it => CheckMatch(pv.GetVendorItem(it), criteria)))
                {
                    list.Add(pv.GetVendorItem(item));
                }

                items.Clear();
                items.TrimExcess();
            }

            switch (criteria.SortBy)
            {
                case SortBy.None: break;
                case SortBy.LowToHigh: list = list.OrderBy(vi => vi.Price).ToList(); break;
                case SortBy.HighToLow: list = list.OrderBy(vi => -vi.Price).ToList(); break;
            }

            return list;
        }
开发者ID:Crome696,项目名称:ServUO,代码行数:30,代码来源:VendorSearch.cs

示例8: SortCars

        public List<Car> SortCars(string sortOrder, List<Car> carsList)
        {
            List<Car> SortedList;
            switch (sortOrder)
            {
                case "price":
                    {
                        SortedList = carsList.OrderBy(o => o.Price).ToList();
                        break;
                    }
                case "mileage":
                    {
                        SortedList = carsList.OrderBy(o => o.Mileage).ToList();
                        break;
                    }
                case "price_desc":
                    {
                        SortedList = carsList.OrderByDescending(o => o.Price).ToList();
                        break;
                    }
                case "mileage_desc":
                    {
                        SortedList = carsList.OrderByDescending(o => o.Mileage).ToList();
                        break;
                    }
                default:

                    SortedList = carsList;
                    break;
            }
            return SortedList;
        }
开发者ID:Naresh-Nelavalli,项目名称:TraumenAuto,代码行数:32,代码来源:Manager.cs

示例9: EncodeParametersFromTypeAttributes

        public byte[] EncodeParametersFromTypeAttributes(Type type, object instanceValue)
        {
            var properties = type.GetTypeInfo().DeclaredProperties;

            var parameterObjects = new List<ParameterAttributeValue>();

            foreach (var property in properties)
                if (property.IsDefined(typeof(ParameterAttribute), false))
                {
                    var parameterAttribute = property.GetCustomAttribute<ParameterAttribute>();
                    var propertyValue = property.GetValue(instanceValue);
                    parameterObjects.Add(new ParameterAttributeValue
                    {
                        ParameterAttribute = parameterAttribute,
                        Value = propertyValue
                    });
                }

            var abiParameters =
                parameterObjects.OrderBy(x => x.ParameterAttribute.Order)
                    .Select(x => x.ParameterAttribute.Parameter)
                    .ToArray();
            var objectValues = parameterObjects.OrderBy(x => x.ParameterAttribute.Order).Select(x => x.Value).ToArray();
            return EncodeParameters(abiParameters, objectValues);
        }
开发者ID:Nethereum,项目名称:Nethereum,代码行数:25,代码来源:ParametersEncoder.cs

示例10: Index

        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            //WebClient wc = new WebClient();
            string pageData;
            //pageData = wc.DownloadString("http://www.fundamentus.com.br/resultado.php");
            PostSubmitter post = new PostSubmitter();
            post.Url = "http://www.fundamentus.com.br/resultado.php";
            post.PostItems.Add("pl_min", "1");
            post.PostItems.Add("pl_max", "20");
            post.PostItems.Add("roe_min", "0");
            post.PostItems.Add("pvp_min", "0");
            post.PostItems.Add("pvp_max", "10");
            post.PostItems.Add("liqcorr_min", "1");
            post.PostItems.Add("margemebit_min", "0");
            post.PostItems.Add("tx_cresc_rec_min", "0.08");
            post.PostItems.Add("liq_min", "100000");
            pageData = post.Post();

            List<Stock> stocks = new List<Stock>();
            HTMLSearchResult searcher = new HTMLSearchResult();
            HTMLSearchResult result;

            int i = 0;
            for (i = 0; i < 20; i++ )
            {
                result = searcher.GetTagData(pageData, "html", 1).GetTagData("body").
                            GetTagData("table").GetTagData("tr", i + 2).GetTagData("td").GetTagData("span").GetTagData("a");
                Stock stock = new Stock
                {
                    Name = result.TAGData
                };
                result = searcher.GetTagData(pageData, "html", 1).GetTagData("body").
                            GetTagData("table").GetTagData("tr", i + 2).GetTagData("td", 3);
                stock.PL = Convert.ToDouble(result.TAGData);
                result = searcher.GetTagData(pageData, "html", 1).GetTagData("body").
                            GetTagData("table").GetTagData("tr", i + 2).GetTagData("td", 16);
                stock.ROE = Convert.ToDouble(result.TAGData.Split('%').First());
                if (stock.PL > 1 && stock.PL < 20 && stock.ROE > 0)
                    stocks.Add(stock);

            }
            stocks = stocks.OrderBy(a => a.PL).ToList();
            i = 1;
            foreach (var stock in stocks)
            {
                stock.PLPosition = i;
                i++;
            }
            stocks = stocks.OrderByDescending(a => a.ROE).ToList();
            i = 1;
            foreach (var stock in stocks)
            {
                stock.ROEPosition = i;
                stock.Position = stock.PLPosition + stock.ROEPosition;
                i++;
            }

            return View(stocks.OrderBy(a=>a.Position).ToList());
        }
开发者ID:anishihara,项目名称:Magic-Formula,代码行数:60,代码来源:HomeController.cs

示例11: SortAuditoriums

        public List<Auditorium> SortAuditoriums(List<Auditorium> list, int buildingIndex)
        {
            var building = _repo.Buildings.GetFirstFiltredBuilding(b => b.BuildingId == buildingIndex);
            if (building != null)
            {
                if (building.Name == "ул. Молодогвардейская, 196")
                {
                    var result = new List<Auditorium>();
                    var a3 = list
                        .Where(a => a.Name.Length >= 6 && a.Name.Substring(5, 1) == "3")
                        .OrderBy(a => a.Name)
                        .ToList();
                    foreach (var a in a3)
                    {
                        result.Add(a);
                        list.Remove(a);
                    }
                    var a1 = list
                        .Where(a => a.Name.Length >= 6 && a.Name.Substring(5, 1) == "1")
                        .OrderBy(a => a.Name)
                        .ToList();
                    foreach (var a in a1)
                    {
                        result.Add(a);
                        list.Remove(a);
                    }
                    result.AddRange(list.OrderBy(a => a.Name));
                    return result;
                }
            }

            return list.OrderBy(a => a.Name).ToList();
        }
开发者ID:BesuglovS,项目名称:UchOtd,代码行数:33,代码来源:BuildingLessons.cs

示例12: GetTumblePos

        public static Vector3 GetTumblePos(this Obj_AI_Base target)
        {
            if (!target.IsMelee && Player.Instance.CountEnemiesInRange(800) == 1) return Game.CursorPos;

            var aRc = new Circle(Player.Instance.ServerPosition.To2D(), 300).ToClipperPath();
            var cursorPos = Game.CursorPos;
            var targetPosition = target.ServerPosition;
            var pList = new List<Vector3>();
            var additionalDistance = (0.106 + Game.Ping / 2000f) * target.MoveSpeed;

            if (!cursorPos.IsDangerousPosition()) return cursorPos;

            foreach (var v3 in aRc.Select(p => new Vector2(p.X, p.Y).To3D()))
            {
                if (target.IsFacing(Player.Instance))
                {
                    if (!v3.IsDangerousPosition() && v3.Distance(targetPosition) < 550) pList.Add(v3);
                }
                else
                {
                    if (!v3.IsDangerousPosition() && v3.Distance(targetPosition) < 550 - additionalDistance) pList.Add(v3);
                }
            }
            if (Player.Instance.UnderTurret() || Player.Instance.CountEnemiesInRange(800) == 1)
            {
                return pList.Count > 1 ? pList.OrderBy(el => el.Distance(cursorPos)).FirstOrDefault() : Vector3.Zero;
            }
            if (!cursorPos.IsDangerousPosition())
            {
                return pList.Count > 1 ? pList.OrderBy(el => el.Distance(cursorPos)).FirstOrDefault() : Vector3.Zero;
            }
            return pList.Count > 1 ? pList.OrderByDescending(el => el.Distance(cursorPos)).FirstOrDefault() : Vector3.Zero;
        }
开发者ID:himrengod,项目名称:Elobuddy-1,代码行数:33,代码来源:O4WExtensions.cs

示例13: FetchListOfChildren

        public JqGridData FetchListOfChildren(Person currentPerson, JqGridRequest request, string[] selectedRoles)
        {
            IEnumerable<ChildReportDto> listOfChildren = new List<ChildReportDto>();
            try
            {
                listOfChildren = _childrenReportsRepository.GetListOfChildrenForAChurch(currentPerson, ConversionService.ConvertSelectedRolesToListOfInts(selectedRoles));
            }
            catch (Exception ex)
            {
                _emailService.SendExceptionEmail(ex);
            }

            var totalRecords = listOfChildren.Count();

            switch (request.sidx)
            {
                case "Age":
                    {
                        listOfChildren = request.sord.ToLower() == "asc" ? listOfChildren.OrderBy(p => p.Age).Skip((request.page - 1) * request.rows).Take(request.rows) : listOfChildren.OrderByDescending(p => p.Age).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
                case "Surname":
                    {
                        listOfChildren = request.sord.ToLower() == "asc" ? listOfChildren.OrderBy(p => p.Surname).Skip((request.page - 1) * request.rows).Take(request.rows) : listOfChildren.OrderByDescending(p => p.Surname).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
                case "Firstname":
                    {
                        listOfChildren = request.sord.ToLower() == "asc" ? listOfChildren.OrderBy(p => p.Firstname).Skip((request.page - 1) * request.rows).Take(request.rows) : listOfChildren.OrderByDescending(p => p.Firstname).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
            }

            var childrenGridData = new JqGridData()
            {
                total = (int) Math.Ceiling((float) totalRecords/request.rows),
                page = request.page,
                records = totalRecords,
                rows = (from p in listOfChildren.AsEnumerable()
                    select new JqGridRow()
                    {
                        id = p.PersonId.ToString(),
                        cell = new[]
                        {
                            p.PersonId.ToString(),
                            p.Age.ToString(),
                            p.Firstname,
                            p.Surname,
                            p.CellNo,
                            p.GroupName,
                            p.Father,
                            p.Mother

                        }
                    }).ToArray()
            };

            return childrenGridData;
        }
开发者ID:petermunnings,项目名称:funwithoiky,代码行数:59,代码来源:ChildReportsService.cs

示例14: createShip

        public IShip createShip(List<Coordinates> Coords, List<IShip> ships)
        {
            foreach (IShip ship in ships)     // walidacja etap pierwszy sprawdzanie czy nasz statek nachodzi na inny
            {
                foreach (Coordinates pice_of_ship in ship)
                {
                    foreach (Coordinates item in Coords)
                    {
                        if (item.x == pice_of_ship.x && item.y == pice_of_ship.y)
                        {
                            return null;
                        }

                        if (item.x + 1 == pice_of_ship.x && item.y == pice_of_ship.y)
                        {
                            return null;
                        }
                        else if (item.x - 1 == pice_of_ship.x && item.y == pice_of_ship.y)
                        {
                            return null;
                        }
                        else if (item.y + 1 == pice_of_ship.y && item.x == pice_of_ship.x)
                        {
                            return null;
                        }
                        else if (item.y - 1 == pice_of_ship.y && item.x == pice_of_ship.x)
                        {
                            return null;
                        }
                    }
                }
            }
            List<Coordinates> sorted = Coords.OrderBy(o => o.x).ToList();
            List<Coordinates> sorted2 = Coords.OrderBy(o => o.y).ToList();

            if (sorted.ElementAt(0).x + 3 == sorted.ElementAt(1).x + 2
                && sorted.ElementAt(1).x + 2 == sorted.ElementAt(2).x + 1
                && sorted.ElementAt(2).x + 1 == sorted.ElementAt(3).x &&
                sorted2.ElementAt(0).y == sorted2.ElementAt(1).y
                && sorted2.ElementAt(1).y == sorted2.ElementAt(2).y
                && sorted2.ElementAt(2).y == sorted2.ElementAt(3).y)
            {
                return new ShipFourMast(Coords, "red");
            }
            else if (sorted.ElementAt(0).x == sorted.ElementAt(1).x
                && sorted.ElementAt(1).x == sorted.ElementAt(2).x
                && sorted.ElementAt(2).x == sorted.ElementAt(3).x &&
                sorted2.ElementAt(0).y + 3 == sorted2.ElementAt(1).y + 2
                && sorted2.ElementAt(1).y + 2 == sorted2.ElementAt(2).y + 1
                && sorted2.ElementAt(2).y + 1 == sorted2.ElementAt(3).y)
                {
                return new ShipFourMast(Coords, "red");
                }
            else
                return null;
      
        }
开发者ID:gornikp,项目名称:ZTP,代码行数:57,代码来源:ShipFourMastFactory.cs

示例15: Main

        /// <summary>
        /// Main entry
        /// </summary>
        /// <param name="args"> Command line parameters </param>
        public static void Main(string[] args)
        {
            var separator = "|";
            var field = 0;
            bool verbose = false, numeric = false;
            string file = null, file2 = null;

            var opts = new GetOpt(
                "Sample application that sorts input rows based on a delimeted field",
                new[]
                    {
                        new CommandLineOption('s', "separator", "Field separator", ParameterType.String, o => separator = (string)o),
                        new CommandLineOption('v', "verbose", "Show more info about found files", ParameterType.None, o => verbose = true),
                        new CommandLineOption('V', null, "Show version", ParameterType.None, o => Console.WriteLine("Version: 1.0")),
                        new CommandLineOption('B', null, "set B", ParameterType.String, o => Console.WriteLine("Version: 1.0")),
                        new CommandLineOption('\0', "numeric", "sort numerically", ParameterType.None, o => numeric = true),
                        new CommandLineOption('f', "field", "Which field to sort by. Default = 0", ParameterType.Integer, o => field = (int)o),
                        new CommandLineOption("file", ParameterType.String, o => file = (string)o),
                        new CommandLineOption("file2", ParameterType.String, o => file2 = (string)o, true),
                    });

            try
            {
                opts.ParseOptions(args);
            }
            catch (CommandLineException e)
            {
                Console.WriteLine("Error: {0}", e.Message);
                return;
            }

            if (verbose) Console.WriteLine("Starting...");

            // Read given file or standard input, split it up according to delimiter and sort by given field. No error handling, this is an example ;)
            StreamReader input = file != null ? new StreamReader(file) : new StreamReader(Console.OpenStandardInput());
            string line;
            var s = new List<Tuple<string, string>>();
            while ((line = input.ReadLine()) != null)
            {
                var key = line.Split(separator[0])[field];
                s.Add(new Tuple<string, string>(key, line));
            }

            foreach (var linepair in numeric ? s.OrderBy(x => int.Parse(x.Item1)) : s.OrderBy(x => x.Item1))
            {
                Console.WriteLine(linepair.Item2);
            }

            if (opts.AdditionalParameters.Count > 1)
            {
                // Handle additional files here
                foreach (var additionalParameter in opts.AdditionalParameters)
                {
                    Console.WriteLine("Another parameter '{0}' was included", additionalParameter);
                }
            }
        }
开发者ID:jokedst,项目名称:GetOpt,代码行数:61,代码来源:Program.cs


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