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


C# System.Collections.Generic.Select方法代码示例

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


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

示例1: FeatureSerialization

        public void FeatureSerialization()
        {
            var coordinates = new[]
            {
                new List<IPosition>
                {
                    new GeographicPosition(52.370725881211314, 4.889259338378906),
                    new GeographicPosition(52.3711451105601, 4.895267486572266),
                    new GeographicPosition(52.36931095278263, 4.892091751098633),
                    new GeographicPosition(52.370725881211314, 4.889259338378906)
                },
                new List<IPosition>
                {
                    new GeographicPosition(52.370725881211314, 4.989259338378906),
                    new GeographicPosition(52.3711451105601, 4.995267486572266),
                    new GeographicPosition(52.36931095278263, 4.992091751098633),
                    new GeographicPosition(52.370725881211314, 4.989259338378906)
                },
            };

            var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
            IGeometryObject geometry;

            geometry = new LineString(coordinates[0]);
            JsonAssert.AssertCoordinates(JsonConvert.SerializeObject(new Feature.Feature(geometry), DefaultJsonSerializerSettings), 1, coordinates[0]);

            geometry = new Point(coordinates[0][0]);
            JsonAssert.AssertCoordinates(JsonConvert.SerializeObject(new Feature.Feature(geometry), DefaultJsonSerializerSettings), 0, coordinates[0].Take(1).ToArray());

            geometry = new MultiLineString(coordinates.Select(ca => new LineString(ca)).ToList());
            JsonAssert.AssertCoordinates(JsonConvert.SerializeObject(new Feature.Feature(geometry), DefaultJsonSerializerSettings), 2, coordinates);

            geometry = new Polygon(coordinates.Select(ca => new LineString(ca)).ToList());
            JsonAssert.AssertCoordinates(JsonConvert.SerializeObject(new Feature.Feature(geometry), DefaultJsonSerializerSettings), 2, coordinates);
        }
开发者ID:tobiashoeft,项目名称:GeoJSON.Net,代码行数:35,代码来源:FeatureCollectionTests.cs

示例2: GetReadStreamTheories

        public static IEnumerable<object[]> GetReadStreamTheories()
        {
            var theories = new[]
            {
                new ReadStreamTheory("stream-1", StreamPosition.Start, ReadDirection.Forward, 2, 
                    new StreamEventsPage("stream-1", PageReadStatus.Success, 0, 2, 2, ReadDirection.Forward, false,
                          ExpectedStreamEvent("stream-1", 1, 0, SystemClock.GetUtcNow().UtcDateTime),
                          ExpectedStreamEvent("stream-1", 2, 1, SystemClock.GetUtcNow().UtcDateTime))),

                new ReadStreamTheory("not-exist", 1, ReadDirection.Forward, 2, 
                    new StreamEventsPage("not-exist", PageReadStatus.StreamNotFound, 1, -1, -1, ReadDirection.Forward, true)),

                new ReadStreamTheory("stream-2", 1, ReadDirection.Forward, 2, 
                    new StreamEventsPage("stream-2", PageReadStatus.Success, 1, 3, 2, ReadDirection.Forward, true,
                          ExpectedStreamEvent("stream-2", 5, 1, SystemClock.GetUtcNow().UtcDateTime),
                          ExpectedStreamEvent("stream-2", 6, 2, SystemClock.GetUtcNow().UtcDateTime))),

                new ReadStreamTheory("stream-1", StreamPosition.End, ReadDirection.Backward, 2, 
                    new StreamEventsPage("stream-1", PageReadStatus.Success, -1, 0, 2, ReadDirection.Backward, false,
                          ExpectedStreamEvent("stream-1", 3, 2, SystemClock.GetUtcNow().UtcDateTime),
                          ExpectedStreamEvent("stream-1", 2, 1, SystemClock.GetUtcNow().UtcDateTime))),

                 new ReadStreamTheory("stream-1", StreamPosition.End, ReadDirection.Backward, 4, 
                    new StreamEventsPage("stream-1", PageReadStatus.Success, -1, -1, 2, ReadDirection.Backward, true,
                          ExpectedStreamEvent("stream-1", 3, 2, SystemClock.GetUtcNow().UtcDateTime),
                          ExpectedStreamEvent("stream-1", 2, 1, SystemClock.GetUtcNow().UtcDateTime),
                          ExpectedStreamEvent("stream-1", 1, 0, SystemClock.GetUtcNow().UtcDateTime)))
            };

            return theories.Select(t => new object[] { t });
        }
开发者ID:robvdlv,项目名称:Cedar.EventStore,代码行数:31,代码来源:EventStoreAcceptanceTests.ReadStream.cs

示例3: NURBS1

        public static void NURBS1()
        {
            // Draw a simple NURBS
            // Example from this page:http://www.robthebloke.org/opengl_programming.html

            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            var points = new[]
                             {
                                 new VA.Drawing.Point(10, 10),
                                 new VA.Drawing.Point(5, 10),
                                 new VA.Drawing.Point(-5, 5),
                                 new VA.Drawing.Point(-10, 5),
                                 new VA.Drawing.Point(-4, 10),
                                 new VA.Drawing.Point(-4, 5),
                                 new VA.Drawing.Point(-8, 1)
                             };

            var origin = new VA.Drawing.Point(4, 4);
            var scale = new VA.Drawing.Size(1.0/4.0, 1.0/4.0);

            var controlpoints = points.Select(x => (x*scale) + origin).ToList();
            var knots = new double[] {0, 0, 0, 0, 1, 2, 3, 4, 4, 4, 4};
            var degree = 3;
            var weights = controlpoints.Select(i => 1.0).ToList();

            var s0 = page.DrawNURBS(controlpoints, knots, weights, degree);
            s0.Text = "Generic NURBS shape";
        }
开发者ID:firestream99,项目名称:VisioAutomation,代码行数:29,代码来源:SimpleGeometrySamples.cs

示例4: TestIsAHuman

        public void TestIsAHuman()
        {
            // Arrange
            var verifier = new UserAgentVerifier();
            var userAgents = new[]
            {
                // IE
                "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko",

                // Chrome
                "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36",

                // Firefox
                "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0",

                // Safari
                "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",

                // Opera
                "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.132 Safari/537.36 OPR/21.0.1432.57 (Edition Campaign 51)", // opera

                // Yandex.Browser
                "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.5 (KHTML, like Gecko) YaBrowser/1.0.1084.5402 Chrome/19.0.1084.5402 Safari/536.5",
                "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.5 (KHTML, like Gecko) YaBrowser/1.0.1084.5402 Chrome/19.0.1084.5402 Safari/536.5",
                "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) YaBrowser/1.0.1084.5402 Chrome/19.0.1084.5402 Safari/536.5",
                "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.12785 YaBrowser/13.12.1599.12785 Safari/537.36"
            };

            // Act
            IEnumerable<bool> results = userAgents.Select(verifier.IsBot);

            // Assert
            Assert.True(results.All(r => !r));
        }
开发者ID:GusLab,项目名称:video-portal,代码行数:34,代码来源:UserAgentVerifierTests.cs

示例5: Test

	IEnumerable<ushort> Test ()
	{
		string[] s = new[] { "a", "b", "c" };

		var m = s.Select (l => ctx.Foo (l)).ToArray ();

		yield break;
	}
开发者ID:nobled,项目名称:mono,代码行数:8,代码来源:gtest-iter-31.cs

示例6: ComplexValueTest

        public void ComplexValueTest()
        {
            EdmModel model = new EdmModel();

            var emptyComplexType = new EdmComplexType(DefaultNamespaceName, "EmptyComplexType");
            model.AddElement(emptyComplexType);

            var complexTypeWithStringProperty = new EdmComplexType(DefaultNamespaceName, "ComplexTypeWithStringProperty");
            complexTypeWithStringProperty.AddStructuralProperty("stringProperty", EdmCoreModel.Instance.GetString(isNullable: true));
            complexTypeWithStringProperty.AddStructuralProperty("numberProperty", EdmCoreModel.Instance.GetInt32(isNullable: false));
            model.AddElement(complexTypeWithStringProperty);

            model.Fixup();
            

            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                // Empty element is a valid complex value
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.ComplexValue("TestModel.EmptyComplexType")
                        .XmlValueRepresentation(new XNode[0])
                        .WithTypeAnnotation(emptyComplexType),
                    PayloadEdmModel = model
                },
            };

            testDescriptors = testDescriptors.Concat(
                PropertiesElementAtomValues.CreatePropertiesElementPaddingPayloads<ComplexInstance>(
                    new PayloadReaderTestDescriptor(this.Settings)
                    {
                        PayloadElement = PayloadBuilder.ComplexValue("TestModel.ComplexTypeWithStringProperty")
                            .WithTypeAnnotation(complexTypeWithStringProperty),
                        PayloadEdmModel = model
                    },
                    (complexInstance, xmlValue) => complexInstance.XmlValueRepresentation(xmlValue)));

            testDescriptors = testDescriptors.Select(td => td.InProperty());

            testDescriptors = testDescriptors.Concat(new []
            {
                // Top-level property without expected type and no type name - this is read as primitive string!
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Property(null, PayloadBuilder.PrimitiveValue(string.Empty))
                        .XmlRepresentation("<m:value/>"),
                    PayloadEdmModel = model,
                },
            });

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.AtomFormatConfigurations,
                (testDescriptor, testConfiguration) =>
                {
                    testDescriptor.RunTest(testConfiguration);
                });
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:58,代码来源:ComplexValueReaderAtomTests.cs

示例7: PickNone

        public void PickNone()
        {
            var solver = new UnboundedDPKnapsackSolver();
            IEnumerable<int> seq = new[] { 10, 20, 30, };
            IEnumerable<IItem> items = seq.Select(item => new IntItem(item));
            IEnumerable<IItem> knapsack = solver.Solve(items, 0);

            Assert.AreEqual(0, knapsack.Count());
        }
开发者ID:helios2k6,项目名称:Knapsack,代码行数:9,代码来源:UnboundedKnapsack.cs

示例8: PickMany

        public void PickMany()
        {
            var solver = new UnboundedDPKnapsackSolver();
            IEnumerable<int> seq = new[] { 1, 2, 3, 4, 5 };
            IEnumerable<IItem> items = seq.Select(item => new IntItem(item));
            IEnumerable<IItem> knapsack = solver.Solve(items, 10);

            Assert.AreEqual(10, knapsack.Sum(item => item.Value));
            Assert.AreEqual(10, knapsack.Sum(item => item.Weight));
        }
开发者ID:helios2k6,项目名称:Knapsack,代码行数:10,代码来源:UnboundedKnapsack.cs

示例9: DontCompleteOne

 public void DontCompleteOne()
 {
     var taskCompletionSources = new []
                                 {
                                     new TaskCompletionSource<int>(), 
                                     new TaskCompletionSource<int>()
                                 };
     var whenAllTask = TaskUtils.WhenAll(taskCompletionSources.Select(tcs => tcs.Task));
     taskCompletionSources[0].SetResult(1);
     Assert.IsFalse(whenAllTask.IsCompleted);
 }
开发者ID:JakeGinnivan,项目名称:AsyncBridge,代码行数:11,代码来源:WhenAllTests.cs

示例10: returns_enumerable_of_different_type

        public void returns_enumerable_of_different_type()
        {
            List<string> names = new[] {"Luke", "Yoda", "Anakin"}.ToList();

            IEnumerable<Jedi> jedi = names.Select(n => new Jedi(n));

            jedi.Count().ShouldBe(3);
            jedi.ElementAt(0).Name.ShouldBe("Luke");
            jedi.ElementAt(1).Name.ShouldBe("Yoda");
            jedi.ElementAt(2).Name.ShouldBe("Anakin");
        }
开发者ID:RookieOne,项目名称:Learning,代码行数:11,代码来源:select_tests.cs

示例11: SoundsLike_SearchMultipleWords_ReturnsAllMatchingRecords

        public void SoundsLike_SearchMultipleWords_ReturnsAllMatchingRecords()
        {
            //Arrange
            var names = new[] {"Robert", "Mitt"};
            var soundexCodes = names.Select(w => w.ToSoundex());
            var expected = _testData.Where(td => soundexCodes.Contains(td.Name.ToSoundex()));

            //Act
            var result = _testData.Search(x => x.Name).Soundex("Robert", "Mitt");

            //Assert
            CollectionAssert.AreEqual(expected, result);
        }
开发者ID:ninjanye,项目名称:SearchExtensions,代码行数:13,代码来源:SoundexSearchTests.cs

示例12: NonGenericVersion

 public async Task NonGenericVersion()
 {
     var taskCompletionSources = new []
                                 {
                                     new TaskCompletionSource<int>(), 
                                     new TaskCompletionSource<int>()
                                 };
     var whenAllTask = TaskUtils.WhenAll(taskCompletionSources.Select(tcs => tcs.Task).Cast<Task>());
     taskCompletionSources[0].SetResult(1);
     Assert.IsFalse(whenAllTask.IsCompleted);
     taskCompletionSources[1].SetResult(1);
     await whenAllTask;
 }
开发者ID:JakeGinnivan,项目名称:AsyncBridge,代码行数:13,代码来源:WhenAllTests.cs

示例13: ArrayVersion

 public async Task ArrayVersion()
 {
     var taskCompletionSources = new[]
                                 {
                                     new TaskCompletionSource<int>(), 
                                     new TaskCompletionSource<int>()
                                 };
     Task whenAllTask = TaskUtils.WhenAll(taskCompletionSources.Select(tcs => tcs.Task).ToArray());
     taskCompletionSources[0].SetResult(1);
     Assert.IsFalse(whenAllTask.IsCompleted);
     taskCompletionSources[1].SetResult(1);
     await whenAllTask;
 }
开发者ID:JakeGinnivan,项目名称:AsyncBridge,代码行数:13,代码来源:WhenAllTests.cs

示例14: GivenPublicField_WhenInvokeDataSelector_ThenCategoriesPropertyMatches

        public void GivenPublicField_WhenInvokeDataSelector_ThenCategoriesPropertyMatches()
        {
            string[] expected = new[] { "category1", "category2", "category3" };
            PublicField customField = new PublicField
            {
                Categories = expected.Select(c => new CustomFieldCategory { Name = c }).ToList(),
                CustomFieldType = new CustomFieldType()
            };
            PublicFieldClientDataTable target = new PublicFieldClientDataTable(MockRequest);

            dynamic actual = target.DataSelector.Compile().Invoke(customField);

            CollectionAssert.AreEqual(expected, ((IEnumerable<string>)actual.Categories).ToList());
        }
开发者ID:modulexcite,项目名称:StudentSuccessDashboard,代码行数:14,代码来源:PublicFieldClientDataTableTest.cs

示例15: GetPreloadImageSourcePaths

 private IEnumerable<string> GetPreloadImageSourcePaths()
 {
     var wwwrootFolderPath = Path.Combine(_appEnvironment.ApplicationBasePath, "wwwroot");
     var imagesFolderPath = Path.Combine(wwwrootFolderPath, "images");
     var cupsFolderPath = Path.Combine(imagesFolderPath, "cups");
     var cupTitlesFolderPath = Path.Combine(imagesFolderPath, "cup-titles");
     var trackTitlesFolderPath = Path.Combine(imagesFolderPath, "track-titles");
     var absoluteImageFilePaths = new[] {cupsFolderPath, cupTitlesFolderPath, trackTitlesFolderPath}
         .SelectMany(path => Directory.EnumerateFiles(path, "*.png", SearchOption.AllDirectories));
     var wwwrootFolderPathLength = wwwrootFolderPath.Length;
     return
         absoluteImageFilePaths.Select(
             path => path.Substring(wwwrootFolderPathLength).Replace(@"\", "/"));
 }
开发者ID:jordanmorris,项目名称:MarioKartWiiTrackPicker,代码行数:14,代码来源:HomeController.cs


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