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


C# System.Linq.Select方法代码示例

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


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

示例1: ChartImage

        public void ChartImage()
        {
            var products = new[]
            {
                new Product {Name = "Kayak", Category = "Watersports", Price = 275m},
                new Product {Name = "Lifejacket", Category = "Watersports", Price = 48.95m},
                new Product {Name = "Soccer ball", Category = "Football", Price = 19.50m},
                new Product {Name = "Corner flags", Category = "Football", Price = 34.95m},
                new Product {Name = "Thinking cap", Category = "Chess", Price = 16m},
            };

            Chart chart = new Chart(600, 200,
                                    @"<Chart BackColor=""Gray"" BackSecondaryColor=""WhiteSmoke""
            BackGradientStyle=""DiagonalRight"" AntiAliasing=""All""
            BorderlineDashStyle = ""Solid"" BorderlineColor = ""Gray"">
            <BorderSkin SkinStyle = ""Emboss"" />
            <ChartAreas>
            <ChartArea Name=""Default"" _Template_=""All"" BackColor=""Wheat""
            BackSecondaryColor=""White"" BorderColor=""64, 64, 64, 64""
            BorderDashStyle=""Solid"" ShadowColor=""Transparent"">
            </ChartArea>
            </ChartAreas>
            </Chart>");

            chart.AddSeries(
                chartType: "Column",
                yValues: products.Select(p => p.Price).ToArray(),
                xValue: products.Select(p => p.Name).ToArray()
            );

            chart.Write();
        }
开发者ID:aistrate,项目名称:ProAspNetMvc3,代码行数:32,代码来源:HomeController.cs

示例2: CompareOk

        public void CompareOk()
        {
            var predicates = checker.PredicatesList;

            var hands = new[] { "A♠ 2♥ 3♣ 9♦ Q♥", "2♠ 2♥ 3♣ 4♦ 6♥", "2♠ 2♥ 3♣ 3♦ 6♥", "2♠ 2♥ 2♣ 3♦ 6♥", "2♠ 5♠ 7♠ 9♠ J♠", "2♠ 3♥ 4♣ 5♦ 6♥", "2♠ 2♥ 2♣ 3♦ 3♥", "2♠ 2♥ 2♣ 2♦ 6♥", "2♠ 3♠ 4♠ 5♠ 6♠", "2♠ 2♥ 2♣ 2♦ 5♥", "A♠ 2♥ 3♣ 4♦ 5♥", "A♠ Q♥ 0♣ J♦ K♥", "A♠ A♠", "A♠ A♠ 0♣ J♦ K♥ 2♠", "" };

            bool ok = true;
            foreach (var hand1 in hands.Select(h => PokerUtils.ReadHand(h)))
                foreach (var hand2 in hands.Select(h => PokerUtils.ReadHand(h)))
                {
                    if (!checker.IsValidHand(hand1) ||
                        !checker.IsValidHand(hand2))
                        continue;

                    // the indices of the two hands in the predicate list
                    int ii, jj;
                    for (ii = 0; ii < predicates.Count; ii++)
                    {
                        if (predicates[ii](hand1))
                            break;
                    }
                    for (jj = 0; jj < predicates.Count; jj++)
                    {
                        if (predicates[jj](hand2))
                            break;
                    }

                    var cmp = checker.CompareHands(hand1, hand2);
                    if (cmp == 0)
                    {
                        if (ii != jj)
                            ok = false;

                        continue;
                    }

                    // the higher the index, the weaker the hand
                    if (cmp == -1)
                    {
                        if (ii < jj)
                            ok = false;

                        continue;
                    }
                    else
                    {
                        if (ii > jj)
                            ok = false;

                        continue;
                    }
                }

            Assert.IsTrue(ok);
        }
开发者ID:Elinos,项目名称:TelerikAcademy,代码行数:55,代码来源:PokerHandsCheckerTest.cs

示例3: PicksCorrectVariablesInSimpleCase

        public void PicksCorrectVariablesInSimpleCase()
        {
            // Predicate p(X,Y) :- q(X, Z), r(Z,Y) should have Z and Y as permanent variables
            var p = Literal.NewAtom();
            var q = Literal.NewAtom();
            var r = Literal.NewAtom();

            var X = Literal.NewVariable();
            var Y = Literal.NewVariable();
            var Z = Literal.NewVariable();

            var pXY = Literal.NewFunctor(2).With(X, Y);
            var qXZ = Literal.NewFunctor(2).With(X, Z);
            var rZY = Literal.NewFunctor(2).With(Z, Y);

            // Create the clause
            var clause = Clause.If(qXZ, rZY).Then(pXY);

            // Compile to assignments
            var allPredicates = new[] { clause.Implies }.Concat(clause.If).ToArray();
            var assignmentList = allPredicates.Select(predicate => PredicateAssignmentList.FromPredicate(predicate));

            // Get the set of permanent variables
            var permanent = PermanentVariableAssignments.PermanentVariables(assignmentList);

            // Z and Y are the only permanent variables
            Assert.IsFalse(permanent.Contains(X));
            Assert.IsTrue(permanent.Contains(Y));
            Assert.IsTrue(permanent.Contains(Z));
            Assert.AreEqual(2, permanent.Count);
        }
开发者ID:Logicalshift,项目名称:Reason,代码行数:31,代码来源:PermanentVariables.cs

示例4: ReturnsCorrectDistinctPath

        public void ReturnsCorrectDistinctPath()
        {
            var paths = new[]
            {
                Combine("logger.log"),
                Combine("Debug", "logger.log"),
                Combine("bin", "Debug", "logger.log"),
                Combine("C:\\", "App", "bin", "Debug", "logger.log"),
                Combine("D:\\", "App", "bin", "Debug", "logger.log"),
                Combine("C:\\", "App", "bin", "Release", "logger.log"),
                Combine("C:\\", "App", "obj", "Release", "logger.log")
            };

            var expected = new[]
            {
                Combine("logger.log"),
                Combine("Debug", "logger.log"),
                Combine("bin", "..", "logger.log"),
                Combine("C:\\", "..", "logger.log"),
                Combine("D:\\", "..", "logger.log"),
                Combine("bin", "..", "logger.log"),
                Combine("obj", "..", "logger.log")
            };

            var trie = new FileNamer(paths);

            var result = paths.Select(path => trie.GetName(path)).ToArray();

            Assert.Equal(expected, result);
        }
开发者ID:ItsJustSean,项目名称:TailBlazer,代码行数:30,代码来源:FileNamerFixture.cs

示例5: TestTwoElementsAsync

        public async Task TestTwoElementsAsync()
        {
            var testCode = @"%1 Foo
{
}
%1 Bar
{
}";

            var fixedCode = new[]
            {
                @"%1 Foo
{
}
",
                @"%1 Bar
{
}"
            };

            testCode = testCode.Replace("%1", this.Keyword);
            fixedCode = fixedCode.Select(c => c.Replace("%1", this.Keyword)).ToArray();

            DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, this.Keyword.Length + 2);

            await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);

            if (this.SupportsCodeFix)
            {
                await this.VerifyCSharpFixAsync(new[] { testCode }, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
            }
        }
开发者ID:EdwinEngelen,项目名称:StyleCopAnalyzers,代码行数:33,代码来源:FileMayOnlyContainTestBase.cs

示例6: CollectionNoErroronEmptyCollectionnTest

        public void CollectionNoErroronEmptyCollectionnTest()
        {
            var testCases = new[]
                {
                    new
                    {
                        CollectionName = (string)null,
                        PayloadItems = new CollectionWriterTestDescriptor.ItemDescription[0],
                        ExpectedException = (ExpectedException)null,
                    },
                };

            var testDescriptors = testCases.Select(tc =>
                new CollectionWriterTestDescriptor(
                    this.Settings,
                    tc.CollectionName,
                    tc.PayloadItems, 
                    tc.ExpectedException,
                    /*model*/null));

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.WriterTestConfigurationProvider.AtomFormatConfigurationsWithIndent,
                (testDescriptor, testConfig) =>
                {
                    CollectionWriterUtils.WriteAndVerifyCollectionPayload(testDescriptor, testConfig, this.Assert, this.Logger);
                });

        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:29,代码来源:AtomCollectionWriterTests.cs

示例7: CanForwardToMultipleRecipients

        public async Task CanForwardToMultipleRecipients()
        {
            var network = new InMemNetwork();
            var activator = new BuiltinHandlerActivator();

            Using(activator);

            var recipients = new[] { "recipient-A", "recipient-B" }.ToList();

            recipients.ForEach(network.CreateQueue);

            Configure.With(activator)
                .Transport(t => t.UseInMemoryTransport(network, "forwarder"))
                .Routing(t =>
                {
                    t.AddTransportMessageForwarder(async transportMessage => ForwardAction.ForwardTo(recipients));
                })
                .Start();

            await activator.Bus.SendLocal("HEJ MED DIG!!!");

            var transportMessages = await Task.WhenAll(recipients.Select(async queue =>
            {
                var message = await network.WaitForNextMessageFrom(queue);

                return message;
            }));

            Assert.That(transportMessages.Length, Is.EqualTo(2));
        }
开发者ID:rebus-org,项目名称:Rebus,代码行数:30,代码来源:TestTransportMessageForwarding.cs

示例8: 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

示例9: GetBounds

        public Rectangle2D GetBounds()
        {
            float ymin = 0;
            float xmin = 0;
            float xmax = this.Viewport.Width;
            float ymax = this.Viewport.Height;

            var matrix = Matrix.Invert(this.GetMatrix() * SpriteBatchExtensions.GetUndoMatrix(this.Viewport));

            var corners = new[]
                {
                    new Vector2(xmin, ymin),
                    new Vector2(xmax, ymin),
                    new Vector2(xmin, ymax),
                    new Vector2(xmax, ymax),
                };

            var vectors = corners.Select(x => Vector2.Transform(x, matrix)).ToList();

            xmin = vectors.Min(x => x.X);
            xmax = vectors.Max(x => x.X);
            ymin = vectors.Min(x => x.Y);
            ymax = vectors.Max(x => x.Y);

            return new Rectangle2D(xmin, xmax, ymax, ymin);
        }
开发者ID:AndrewHackler,项目名称:shooter,代码行数:26,代码来源:Perspective.cs

示例10: ProcessRecord

 protected override void ProcessRecord()
 {
     var names = new[] {"Tolle", "Sinan", "Frissan", "Ekan"};
     if (!string.IsNullOrEmpty(Prefix))
     {
         names = names.Select(n => Prefix + n).ToArray();
     }
     WriteObject(names);
 }
开发者ID:mirontoli,项目名称:sp-lend-id,代码行数:9,代码来源:Get_DemoNames.cs

示例11: GetItems

        /*begin*/
        public ActionResult GetItems(GridParams g, string[] selectedColumns, bool? choosingColumns)
        {
            //when setting columns from here we don't get the grid defaults, so we have to specify Sortable, Groupable etc.
            var columns = new[]
                              {
                                  new Column { Name = "Id", Width = 70, Order = 1 },
                                  new Column { Name = "Person", Sortable = true, Groupable = true, GroupRemovable = true, Order = 2 },
                                  new Column { Name = "Food", Sortable = true, Groupable = true, GroupRemovable = true, Order = 3 },
                                  new Column { Name = "Location", Sortable = true, Groupable = true, GroupRemovable = true, Order = 4 },
                                  new Column { Name = "Date", Sortable = true, Groupable = true, GroupRemovable = true, Width = 100, Order = 5 },
                                  new Column { Name = "Price", Sortable = true, Groupable = true, GroupRemovable = true, Width = 100, Order = 6 },
                              };

            var baseColumns = new[] { "Id", "Person" };

            //first load
            if (g.Columns.Length == 0)
            {
                g.Columns = columns;
            }

            if (choosingColumns.HasValue && selectedColumns == null)
            {
                selectedColumns = new string[] { };
            }

            if (selectedColumns != null)
            {
                //make sure we always have Id and Person columns
                selectedColumns = selectedColumns.Union(baseColumns).ToArray();

                var currectColumns = g.Columns.ToList();

                //remove unselected columns
                currectColumns = currectColumns.Where(o => selectedColumns.Contains(o.Name)).ToList();

                //add missing columns
                var missingColumns = selectedColumns.Except(currectColumns.Select(o => o.Name)).ToArray();

                currectColumns.AddRange(columns.Where(o => missingColumns.Contains(o.Name)));

                g.Columns = currectColumns.ToArray();
            }

            var gridModel = new GridModelBuilder<Lunch>(Db.Lunches.AsQueryable(), g).Build();

            // used to populate the checkboxlist
            gridModel.Tag =
                new
                    {
                        columns = columns.Select(o => o.Name).Except(baseColumns).ToArray(),
                        selectedColumns = g.Columns.Select(o => o.Name).Except(baseColumns).ToArray()
                    };

            return Json(gridModel);
        }
开发者ID:russellsamantha,项目名称:Git_Work,代码行数:57,代码来源:GridChooseColumnsDemoController.cs

示例12: Test1To20

        public void Test1To20()
        {
            var target = new FizzBuzz();
            var collection = new[] { "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz" };

            foreach (var item in collection.Select((value, index) => new { Index = index + 1, Value = value }))
            {
                Assert.That(target.Compute(item.Index), Is.EqualTo(item.Value));
            }
        }
开发者ID:ernestohs,项目名称:csharp.katas.simple,代码行数:10,代码来源:FizzBuzz.Test.cs

示例13: GetExtensionReturnsEmptyStringForPathsThatDoNotContainExtension

        public void GetExtensionReturnsEmptyStringForPathsThatDoNotContainExtension() {
            // Arrange
            string[] paths = new[] { "SomePath", "SomePath/", "SomePath/MorePath", "SomePath/MorePath/" };

            // Act
            var extensions = paths.Select(PathUtil.GetExtension);

            // Assert
            Assert.IsTrue(extensions.All(ext => ext.Length == 0));
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:10,代码来源:PathUtilTest.cs

示例14: GetExtensionReturnsEmptyStringForPathsContainingPathInfo

        public void GetExtensionReturnsEmptyStringForPathsContainingPathInfo() {
            // Arrange
            string[] paths = new[] { "SomePath.cshtml/", "SomePath.html/path/info" };

            // Act
            var extensions = paths.Select(PathUtil.GetExtension);

            // Assert
            Assert.IsTrue(extensions.All(ext => ext.Length == 0));
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:10,代码来源:PathUtilTest.cs

示例15: GetExtensionReturnsEmptyStringForPathsTerminatingWithADot

        public void GetExtensionReturnsEmptyStringForPathsTerminatingWithADot() {
            // Arrange
            string[] paths = new[] { "SomePath.", "SomeDirectory/SomePath/SomePath.", "SomeDirectory/SomePath.foo." };

            // Act
            var extensions = paths.Select(PathUtil.GetExtension);

            // Assert
            Assert.IsTrue(extensions.All(ext => ext.Length == 0));
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:10,代码来源:PathUtilTest.cs


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