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


C# City.OrderBy方法代码示例

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


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

示例1: TestGetNearestNeighbours

        public void TestGetNearestNeighbours()
        {
            var toowoomba = new City()
            {
                Address = "Toowoomba, QLD, Australia",
                Lat = -27.5829487f,
                Long = 151.8643252f,
                DistanceFromToowoomba = 0
            };

            City[] cities = new City[]
            {
                toowoomba,
                new City()
                {
                    Address = "Brisbane, QLD, Australia",
                    Lat = -27.4710107f,
                    Long = 153.0234489f,
                    DistanceFromToowoomba = 1.16451615177537f
                },
                new City()
                {
                    Address = "Goldcoast, QLD, Australia",
                    Lat = -28.0172605f,
                    Long = 153.4256987f,
                    DistanceFromToowoomba = 1.6206523211724f
                },
                new City()
                {
                    Address = "Sunshine, QLD, Australia",
                    Lat = -27.3748288f,
                    Long = 153.0554193f,
                    DistanceFromToowoomba = 1.20913979664506f
                },
                new City()
                {
                    Address = "Melbourne, VIC, Australia",
                    Lat = -37.814107f,
                    Long = 144.96328f,
                    DistanceFromToowoomba = 12.3410301438779f
                },
                new City()
                {
                    Address = "Sydney, NSW, Australia",
                    Lat = -33.8674869f,
                    Long = 151.2069902f,
                    DistanceFromToowoomba = 6.31882185929341f
                },
                new City()
                {
                    Address = "Perth, WA, Australia",
                    Lat = -31.9530044f,
                    Long = 115.8574693f,
                    DistanceFromToowoomba = 36.2710774395312f
                },
                new City()
                {
                    Address = "Darwin, NT, Australia",
                    Lat = -12.4628198f,
                    Long = 130.8417694f,
                    DistanceFromToowoomba = 25.895292049265f
                }
                /*,
                new City()
                {
                    Address = "London, England",
                    Lat = 51.5112139f,
                    Long = -0.1198244f,
                    DistanceFromToowoomba = 171.33320836029f

                }*/
            };

            foreach (var city in cities)
            {
                tree.Add(new float[] { city.Long, -city.Lat }, city.Address);
            }

            /*
            var sb = new System.Text.StringBuilder();
            sb.AppendLine("Before Balance:");
            sb.AppendLine(tree.ToString());
            sb.AppendLine("");
            sb.AppendLine("");
            tree.Balance();
            sb.AppendLine("After Balance:");
            sb.AppendLine(tree.ToString());
            System.Windows.Forms.Clipboard.SetText(sb.ToString());
            */

            for (var findLimit = 0; findLimit <= cities.Length; findLimit++)
            {
                var actualNeighbours = tree.GetNearestNeighbours(
                    new float[] { toowoomba.Long, -toowoomba.Lat },
                    findLimit);

                var expectedNeighbours = cities
                    .OrderBy(p => p.DistanceFromToowoomba)
                    .Take(findLimit)
                    .ToArray();
//.........这里部分代码省略.........
开发者ID:ASchvartzman,项目名称:518Project-ASK,代码行数:101,代码来源:KdTreeTests.cs


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