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


C# System.ToList方法代码示例

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


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

示例1: AddStartStopSymbolsTest

        public void AddStartStopSymbolsTest()
        {
            var tokens = new[] {"this", "is", "a", "test"};
            List<string> actual = tokens.ToList();
            List<string> expected = tokens.ToList();
            var model = new NGramModel(Unigram);
            model.AddStartStopSymbols(actual);
            CollectionAssert.AreEqual(expected, actual);

            model = new NGramModel(Bigram);
            actual = tokens.ToList();
            expected = new[] {"<s0>", "this", "is", "a", "test", "</s>"}.ToList();
            model.AddStartStopSymbols(actual);
            CollectionAssert.AreEqual(expected, actual);

            model = new NGramModel(Trigram);
            actual = tokens.ToList();
            expected = new[] {"<s1>", "<s0>", "this", "is", "a", "test", "</s>"}.ToList();
            model.AddStartStopSymbols(actual);
            CollectionAssert.AreEqual(expected, actual);

            model = new NGramModel(4);
            actual = tokens.ToList();
            expected = new[] {"<s2>", "<s1>", "<s0>", "this", "is", "a", "test", "</s>"}.ToList();
            model.AddStartStopSymbols(actual);
            CollectionAssert.AreEqual(expected, actual);
        }
开发者ID:diegolinan,项目名称:nuve,代码行数:27,代码来源:NGramModelTest.cs

示例2: Mod_Test

        public static void Mod_Test()
        {
            var num1 = new[] {23.4m, 45, 0.96m, 31.2m, 0.87m, 0.8m};
            var num2 = 0.5m;

            Console.WriteLine(num1.Select(x => x.ToString()).Aggregate((x, y) => x + "," + y));
            num1.ToList().ForEach(x => Console.WriteLine("{0} 对 {1} 的余数: {2}", x, num2, x%num2));
            Console.WriteLine("-----------------------------------------------------------------");
            num1.ToList().ForEach(x => Console.WriteLine("{0} 项上取整 {1} 数", x, Math.Ceiling(x)));
            Console.WriteLine("-----------------------------------------------------------------");
            num1.ToList().ForEach(x => Console.WriteLine("{0}/0.5 项上取整 {1} 数", x, Math.Ceiling(x/0.5m)));
        }
开发者ID:bikaqiou2000,项目名称:MySDR,代码行数:12,代码来源:MathTest.cs

示例3: BuildCommit

        public static Commit BuildCommit(this Guid streamId)
        {
            const int StreamRevision = 2;
            const int CommitSequence = 2;
            var commitId = Guid.NewGuid();
            var headers = new Dictionary<string, object> { { "Key", "Value" }, { "Key2", (long)1234 }, { "Key3", null } };
            var events = new[]
            {
                new EventMessage
                {
                    Headers =
                    {
                        { "MsgKey1", TimeSpan.MinValue },
                        { "MsgKey2", Guid.NewGuid() },
                        { "MsgKey3", 1.1M },
                        { "MsgKey4", (ushort)1 }
                    },
                    Body = "some value"
                },
                new EventMessage
                {
                    Headers =
                    {
                        { "MsgKey1", new Uri("http://www.google.com/") },
                        { "MsgKey4", "some header" }
                    },
                    Body = new[] { "message body" }
                }
            };

            return new Commit(streamId, StreamRevision, commitId, CommitSequence, SystemTime.UtcNow, headers, events.ToList());
        }
开发者ID:JeetKunDoug,项目名称:EventStore,代码行数:32,代码来源:ExtensionMethods.cs

示例4: OnCreate

		protected override void OnCreate (Bundle savedInstanceState)
		{
			base.OnCreate (savedInstanceState);
			SetContentView (Resource.Layout.recyclerview);

			recyclerView = FindViewById<RecyclerView> (Resource.Id.recycler_view);

			// Layout Managers:
			recyclerView.SetLayoutManager (new LinearLayoutManager (this));

			// Item Decorator:
			recyclerView.AddItemDecoration (new DividerItemDecoration (Resources.GetDrawable (Resource.Drawable.divider)));
			recyclerView.SetItemAnimator (new FadeInLeftAnimator ());

			// Adapter:
			var adapterData = new [] {
				"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", 
				"Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", 
				"Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", 
				"Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", 
				"Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", 
				"New Hampshire", "New Jersey", "New Mexico", "New York", 
				"North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", 
				"Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", 
				"Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", 
				"West Virginia", "Wisconsin", "Wyoming"
			};
			adapter = new RecyclerViewAdapter (this, adapterData.ToList ());
			adapter.Mode = Attributes.Mode.Single;
			recyclerView.SetAdapter (adapter);

			// Listeners
			recyclerView.SetOnScrollListener (new ScrollListener ());
		}
开发者ID:Dealtis,项目名称:oldDMS_3,代码行数:34,代码来源:RecyclerViewExample.cs

示例5: OnCreate

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            SetContentView (Resource.Layout.Main);

            Button button = FindViewById<Button> (Resource.Id.btnRun);

            button.Click += (a, b) =>
            {
                var runs = new[]{
                    new{alg= (IPrime)new AlgorithmAJavaMath(), label= FindViewById<TextView>(Resource.Id.lblAlgAJava), text = "A (java.lang.Math): "},
                    new{alg= (IPrime)new AlgorithmAMonoMath(), label= FindViewById<TextView>(Resource.Id.lblAlgAMono), text = "A (System.Math): "},
                    new{alg= (IPrime)new AlgorithmB(), label= FindViewById<TextView>(Resource.Id.lblAlgB), text = "B: "},
                };

                const int iterations = 100000;

                runs.ToList().ForEach(x =>
                {
                    var elapsed = TheBenchmark.Timed(() =>
                    {
                        for(int i=0; i<iterations; i++)
                        {
                            x.alg.IsPrime(i);
                        }
                    });
                    x.label.Text = x.text + " " + elapsed.TotalMilliseconds;
                });
            };
        }
开发者ID:arlm,项目名称:mobile-benchmark,代码行数:31,代码来源:MainActivity.cs

示例6: OnBeginWorkflowCompleted

        protected override System.IAsyncResult OnBeginWorkflowCompleted(System.Activities.ActivityInstanceState completionState, System.Collections.Generic.IDictionary<string, object> workflowOutputs, System.Exception terminationException, System.TimeSpan timeout, System.AsyncCallback callback, object state) {

            if(terminationException == null) {
                MailMessage mail = new MailMessage();
                mail.To.Add(Email);

                mail.From = new MailAddress("[email protected]");

                mail.Subject = "The workflow has completed";

                StringBuilder stringBuilder = new StringBuilder();
                
                stringBuilder.AppendLine("The result of the workflow was: ");
                
                workflowOutputs.ToList().ForEach(kvp => 
                    stringBuilder.AppendLine(string.Format("{0}: {1}", kvp.Key, kvp.Value))
                );
                
                mail.Body = stringBuilder.ToString();

                mail.IsBodyHtml = false;

                SmtpClient smtp = new SmtpClient();
                smtp.Send(mail);
                
            }

            return base.OnBeginWorkflowCompleted(completionState, workflowOutputs, terminationException, timeout, callback, state);
        }
开发者ID:huoxudong125,项目名称:Demo.EnterpriseWorkflow,代码行数:29,代码来源:EnterpriseWorkflowCreationContext.cs

示例7: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            btnBenchmark.TouchUpInside += (object sender, EventArgs e) =>
            {
                var runs = new[]{
                    new{alg= (IPrime)new AlgorithmAMonoMath(), label= lblStackOverflow, text = "A: "},
                    new{alg= (IPrime)new AlgorithmB(), label= lblPerls, text = "B: "},
                };

                const int iterations = 100000;

                runs.ToList().ForEach(x =>
                {
                    var elapsed = TheBenchmark.Timed(() =>
                    {
                        for(int i=0; i<iterations; i++)
                        {
                            var p = x.alg.IsPrime(i);
                        }
                    });
                    x.label.Text = x.text + " " + elapsed.TotalMilliseconds;
                });
            };
        }
开发者ID:arlm,项目名称:mobile-benchmark,代码行数:26,代码来源:Benchmark.iOSViewController.cs

示例8: SelectByIDs

        public CacheSet<string> SelectByIDs(string EntityName, System.Collections.Generic.IEnumerable<string> EntityIDs)
        {
            CacheSet<string> Result = new CacheSet<string>();

            if (!EntityNames.Contains(EntityName))
            {
                Result.WantIDs = EntityIDs.ToList<string>();

                return Result;
            }

            List<string> IDs = new List<string>();
            List<string> Contents = new List<string>();

            StringBuilder QueryBuilder = new StringBuilder();
            QueryBuilder.AppendFormat("select * from {0} where ID in ({1}) order by ID", EntityName, ToCommaList(EntityIDs));

            DataTable Table = SQLLite.GetDataTable(QueryBuilder.ToString());

            for (int i=0; i < Table.Rows.Count; i++)
            {
                IDs.Add(Table.Rows[i][0].ToString());
                Contents.Add(Table.Rows[i][1].ToString());
            }

            Result.Records = Contents;

            Result.WantIDs = EntityIDs.Except<string>(IDs).ToList<string>();

            return Result;
        }
开发者ID:ChunTaiChen,项目名称:K12.Data,代码行数:31,代码来源:DiskCacheProvider.cs

示例9: GetParsedEntities_should_return_two_entities_when_all_pattern_groups_are_used

        public void GetParsedEntities_should_return_two_entities_when_all_pattern_groups_are_used()
        {
            var correctAnswer = new[] { (Entity)new RawTextEntity("|"), new TestEntity("treasure") };
            var answer = Apply_GetParsedEntities("|treasure|some text|");

            CollectionAssert.AreEqual(correctAnswer.ToList(), answer);
        }
开发者ID:xackill,项目名称:01-quality,代码行数:7,代码来源:Rule_Tests.cs

示例10: MemberBuilder

        public void GivenProductsWithCurrentCampaignWithSomeThatApplyToTheMember_WhenQuerying_ThenReturnTheProductsThatApplyToTheMember()
        {
            var member = new MemberBuilder().InState(State.Wa).WithAge(10, _now).Build();
            var products = new[]
            {
                new ProductBuilder().WithName("1").WithCampaign(_now,
                    new CampaignBuilder()
                        .ForAllMembers()
                        .StartingAt(_now.AddDays(-1))
                        .EndingAt(_now.AddDays(1))
                ).Build(),
                new ProductBuilder().WithName("2").WithCampaign(_now,
                    new CampaignBuilder()
                        .ForState(State.Act)
                        .StartingAt(_now.AddDays(-1))
                        .EndingAt(_now.AddDays(1))
                ).Build(),
                new ProductBuilder().WithName("2").WithCampaign(_now,
                    new CampaignBuilder()
                        .ForState(State.Wa)
                        .WithMinimumAge(9)
                        .WithMaximumAge(11)
                        .StartingAt(_now.AddDays(-1))
                        .EndingAt(_now.AddDays(1))
                ).Build()
            };
            products.ToList().ForEach(p => Session.Save(p));

            var result = Execute(new GetProductsForMember(_now, member));

            Assert.That(result.Select(p => p.Name).ToArray(), Is.EqualTo(new[]{products[0].Name, products[2].Name}));
        }
开发者ID:robdmoore,项目名称:TestFixtureDataGenerationPresentation,代码行数:32,代码来源:GetProductsForMemberTests.cs

示例11: GetParsedEntities_should_return_one_entity_when_first_pattern_group_is_empty

        public void GetParsedEntities_should_return_one_entity_when_first_pattern_group_is_empty()
        {
            var correctAnswer = new[] { (Entity)new TestEntity("treasure") };
            var answer = Apply_GetParsedEntities("treasure|some text|");

            CollectionAssert.AreEqual(correctAnswer.ToList(), answer);
        }
开发者ID:xackill,项目名称:01-quality,代码行数:7,代码来源:Rule_Tests.cs

示例12: EventTest

		public void EventTest ()
		{
			var automationEventsArray = new [] {
				new {Sender = (object) null, Args = (AutomationPropertyChangedEventArgs) null}};
			var automationEvents = automationEventsArray.ToList ();
			automationEvents.Clear ();

			var dock = (DockPattern)
				splitter1Element.GetCurrentPattern (DockPattern.Pattern);

			dock.SetDockPosition (DockPosition.Top);

			SWA.Automation.AddAutomationPropertyChangedEventHandler (splitter1Element,
				TreeScope.Element,
				(o, e) => automationEvents.Add (new { Sender = o, Args = e }),
				DockPattern.DockPositionProperty);

			dock.SetDockPosition (DockPosition.Right);
			Thread.Sleep (200);
			Assert.AreEqual (1, automationEvents.Count, "event count");
			Assert.AreEqual (DockPattern.DockPositionProperty,
				automationEvents [0].Args.Property, "event property");
			Assert.AreEqual (splitter1Element,
				automationEvents [0].Sender, "event sender");
			Assert.AreEqual (3,
				automationEvents [0].Args.NewValue, "event new val");
		}
开发者ID:mono,项目名称:uia2atk,代码行数:27,代码来源:DockPatternTest.cs

示例13: VisitBinary

        protected override Expression VisitBinary(BinaryExpression node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var allowedProperties = new[] { "Project", "Definition", "Number", "Reason", "Quality", "Status", "RequestedBy", "RequestedFor", "StartTime", "FinishTime", "BuildFinished" };

            if (node.NodeType == ExpressionType.OrElse)
            {
                throw new NotSupportedException("Logical OR operators are not supported for Build Custom filters");
            }

            if (node.Left is MemberExpression && node.Right is ConstantExpression)
            {
                var fieldName = (node.Left as MemberExpression).Member.Name;
                var value = (node.Right as ConstantExpression).Value;

                if (!allowedProperties.ToList().Contains(fieldName))
                {
                    throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "You can only filter by the following properties: {0}. (e.g. /Builds/$filter=Number gt 100 and  Quality eq 'Healthy') ", string.Join(", ", allowedProperties)));
                }

                this.AddFilterNode(fieldName, value, FilterNode.ParseFilterExpressionType(node.NodeType), FilterNodeRelationship.And);
            }
            else if (node.Left.NodeType == ExpressionType.Conditional)
            {
                throw new NotSupportedException("Only equality and inequality operators between fields and constant expressions are allowed with Build Custom filters");
            }

            return base.VisitBinary(node);
        }
开发者ID:wullemsb,项目名称:TFS-Monitor,代码行数:33,代码来源:BuildFilterExpressionVisitor.cs

示例14: VisitBinary

        protected override Expression VisitBinary(BinaryExpression node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var allowedProperties = new[] { "Id", "ArtifactUri", "Comment", "Committer", "CreationDate", "Owner", "Branch" };

            if (node.NodeType == ExpressionType.OrElse)
            {
                throw new NotSupportedException("Logical OR operators are not supported for Changeset Custom filters");
            }

            if (node.Left is MemberExpression && node.Right is ConstantExpression)
            {
                var fieldName = (node.Left as MemberExpression).Member.Name;
                var value = (node.Right as ConstantExpression).Value;

                if (!allowedProperties.ToList().Contains(fieldName))
                {
                    throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "You can only filter by the following properties: {0}. (e.g. /Changesets/$filter=Committer eq 'john' and  CreationDate gt datetime'2010-10-18') ", string.Join(", ", allowedProperties)));
                }

                this.AddFilterNode(fieldName, value, FilterNode.ParseFilterExpressionType(node.NodeType), FilterNodeRelationship.And);
            }
            else if (node.Left.NodeType == ExpressionType.Conditional)
            {
                throw new NotSupportedException("Only equality and inequality operators between fields and constant expressions are allowed with Changeset Custom filters");
            }

            return base.VisitBinary(node);
        }
开发者ID:wullemsb,项目名称:TFS-Monitor,代码行数:33,代码来源:ChangesetFilterExpressionVisitor.cs

示例15: PropertyEventTest

		public void PropertyEventTest ()
		{
			var automationEventsArray = new [] {
				new {Sender = (object) null, Args = (AutomationPropertyChangedEventArgs) null}};
			var automationEvents = automationEventsArray.ToList ();
			automationEvents.Clear ();

			string magicStr1 = "ValuePatternTest.PropertyEventTest.m1";
			string magicStr2 = "ValuePatternTest.PropertyEventTest.m2";
			ValuePattern pattern = (ValuePattern) textbox1Element.GetCurrentPattern (ValuePatternIdentifiers.Pattern);
			pattern.SetValue (magicStr1);
			Thread.Sleep (500);

			AutomationPropertyChangedEventHandler handler = 
				(o, e) => automationEvents.Add (new { Sender = o, Args = e });

			At.AddAutomationPropertyChangedEventHandler (textbox1Element,
				TreeScope.Element, handler,
				ValuePattern.ValueProperty,
				ValuePattern.IsReadOnlyProperty );

			pattern.SetValue (magicStr2);
			Thread.Sleep (500);
			Assert.AreEqual (1, automationEvents.Count, "event count");
			Assert.AreEqual (textbox1Element, automationEvents [0].Sender, "event sender");
			Assert.AreEqual (magicStr2, automationEvents [0].Args.NewValue, "new Value");
			// LAMESPEC: The value should be equal to "magicStr1" but is returning null instead
			Assert.IsNull (automationEvents [0].Args.OldValue, "old Value");
			automationEvents.Clear ();

			At.RemoveAutomationPropertyChangedEventHandler (textbox1Element, handler);
			pattern.SetValue (magicStr1);
			Thread.Sleep (500);
			Assert.AreEqual (0, automationEvents.Count, "event count");
		}
开发者ID:mono,项目名称:uia2atk,代码行数:35,代码来源:ValuePatternTest.cs


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