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


C# List.Clear方法代码示例

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


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

示例1: CalculateHeight

        /// <summary>
        /// 计算所需高(暂不考虑英文的word wrapper)
        /// </summary>
        /// <param name="width">目标宽度</param>
        /// <param name="pagePadding">页边距</param>
        /// <param name="lineDistance">行距</param>
        /// <param name="font">字体</param>
        /// <returns>分行完毕的文本</returns>
        private List<string> CalculateHeight(int width, int pagePadding, int lineDistance, PixelFont font, string text)
        {
            List<string> result = new List<string>();
            int availableWidth = width - pagePadding * 2;//除去页边距之后的可用宽度
            List<char> line = new List<char>();
            string[] lines = text.Split(new string[] {"\r\n" }, StringSplitOptions.None);
            int length = 0;
            foreach (var l in lines)
            {
                line.Clear();
                length = 0;
                foreach (var c in l)
                {
                    int len = font.MeasureCharDrawingLength(c);
                    if (len + length > availableWidth)
                    {
                        result.Add(new string(line.ToArray()));
                        line.Clear();
                        line.Add(c);
                        length = len;
                    }
                    else
                    {
                        length += len;
                        line.Add(c);
                    }
                }
                result.Add(new string(line.ToArray()));

            }
            return result;
        }
开发者ID:hoxily,项目名称:DotFont,代码行数:40,代码来源:FormMain.cs

示例2: BuildIndexes

        public async Task BuildIndexes()
        {
            TableQuery<TableUser> query = new TableQuery<TableUser>();
            TableQuerySegment<TableUser> querySegment = null;
            List<Task> insertOperation = new List<Task>();

            while (querySegment == null || querySegment.ContinuationToken != null)
            {
                querySegment = await _userTable.ExecuteQuerySegmentedAsync(query, querySegment != null ? querySegment.ContinuationToken : null);
                foreach (TableUser tableUser in querySegment.Results)
                {
                    TableUserIdIndex indexItem = new TableUserIdIndex(tableUser.UserName, tableUser.Id);
                    insertOperation.Add(_userIndexTable.ExecuteAsync(TableOperation.InsertOrReplace(indexItem)));
                    if (insertOperation.Count > 100)
                    {
                        await Task.WhenAll(insertOperation);
                        insertOperation.Clear();
                    }
                }
                if (insertOperation.Count > 0)
                {
                    await Task.WhenAll(insertOperation);
                    insertOperation.Clear();
                }
            }
        }
开发者ID:muffadalis,项目名称:AccidentalFish.AspNet.Identity.Azure,代码行数:26,代码来源:TableUserIndexBuilder.cs

示例3: Main

    static void Main()
    {
        int[] numbers = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        List<int> temp = new List<int>();
        List<int> longest = new List<int>();

        for (int i = 0, j = 1; i < numbers.Length; i++, j++)
        {
            temp.Add(numbers[i]);

            if ((j < numbers.Length) && (numbers[i] <= numbers[j]))
            {
                continue;
            }
            else
            {
                if (temp.Count > longest.Count)
                {
                    longest.Clear();
                    longest.AddRange(temp);
                    Console.WriteLine(string.Join(" ", temp));
                    temp.Clear();
                }
                else
                {
                    Console.WriteLine(string.Join(" ", temp));
                    temp.Clear();
                }
            }
        }

        Console.WriteLine("Longest: " + string.Join(" ", longest));
    }
开发者ID:borko9696,项目名称:SoftwareUniversity,代码行数:33,代码来源:LongestIncresingSequence.cs

示例4: Handlers_Can_Be_Unsubscribed

        public void Handlers_Can_Be_Unsubscribed()
        {
            var pub = new Publisher();
            var calledSubscribers = new List<int>();
            var sub1 = new InstanceSubscriber(1, pub, calledSubscribers.Add);
            var sub2 = new InstanceSubscriber(2, pub, calledSubscribers.Add);
            StaticSubscriber.FooWasRaised = false;
            StaticSubscriber.Subscribe(pub);

            // Make sure they really were subscribed
            pub.Raise();
            calledSubscribers.Should().Equal(1, 2);
            StaticSubscriber.FooWasRaised.Should().BeTrue();

            calledSubscribers.Clear();
            sub1.Unsubscribe(pub);
            pub.Raise();
            calledSubscribers.Should().Equal(2);

            StaticSubscriber.FooWasRaised = false;
            StaticSubscriber.Unsubscribe(pub);
            pub.Raise();
            StaticSubscriber.FooWasRaised.Should().BeFalse();

            calledSubscribers.Clear();
            sub2.Unsubscribe(pub);
            pub.Raise();
            calledSubscribers.Should().BeEmpty();

            // Make sure subscribers are not collected before the end of the test
            GC.KeepAlive(sub1);
            GC.KeepAlive(sub2);
        }
开发者ID:thomaslevesque,项目名称:WeakEvent,代码行数:33,代码来源:WeakEventSourceTests.cs

示例5: ParseCorrect

        public void ParseCorrect()
        {
            List<string> zList = new List<string>();

            zList.Clear();
            zList.Add("AT+TASKPLANNER?");
            zList.Add("");
            zList.Add("+TASKPLANNER: 0, 11:20, 23:12");
            zList.Add("OK");
            Assert.True(_TaskPlannerCommand.Parse(zList));

            Assert.Equal(SyncMode.CustomSync, _TaskPlannerCommand.DeviceSyncMode);

            Assert.Equal(_TaskPlannerCommand.WindowOpenTime.Hour, 11);
            Assert.Equal(_TaskPlannerCommand.WindowOpenTime.Minute, 20);

            Assert.Equal(_TaskPlannerCommand.ActivityPeriod.Hours, 23);
            Assert.Equal(_TaskPlannerCommand.ActivityPeriod.Minutes, 12);

            zList.Clear();
            zList.Add("+TASKPLANNER: 1, 11:20, 23:12");
            zList.Add("OK");
            Assert.True(_TaskPlannerCommand.Parse(zList));

            Assert.Equal(SyncMode.OperatorSync, _TaskPlannerCommand.DeviceSyncMode);
        }
开发者ID:MegaYanuardi,项目名称:GSMLibrary.Net,代码行数:26,代码来源:TaskPlannerCases.cs

示例6: FlipImagesWithOptionalRetry

        private static void FlipImagesWithOptionalRetry(List<string> imageFilepaths, string targetDirectoryPath)
        {
            while (imageFilepaths.Count > 0)
            {
                try
                {
                    FlipImages(imageFilepaths, targetDirectoryPath);
                    imageFilepaths.Clear();
                }
                catch (AggregateException e)
                {
                    imageFilepaths.Clear();
                    var failedFilepaths = new List<string>();
                    foreach (var exception in e.InnerExceptions)
                    {
                        var flipFailed = exception as FileFlipFailedException;
                        if (flipFailed != null)
                        {
                            failedFilepaths.Add(flipFailed.FailedFilepath);
                        }
                    }

                    Console.WriteLine("The following files could not be flipped due to errors:");
                    Console.WriteLine(string.Join(System.Environment.NewLine, failedFilepaths));

                    Console.Write("Would you like to reprocess them? (y/n): ");
                    if (Console.ReadLine()[0] == 'y')
                    {
                        imageFilepaths.AddRange(failedFilepaths);
                    }
                }
            }
        }
开发者ID:TelerikAcademy,项目名称:Windows-Applications,代码行数:33,代码来源:ExceptionsInParallelLoopsHandling.cs

示例7: Start

        public DialogResult Start(Form parent, ref List<Int32> selectedCommodities)
        { 
            try
            {
                m_selectedCommodities = selectedCommodities;

                this.ShowDialog(parent);

                if(DialogResult == System.Windows.Forms.DialogResult.OK)
                {
                    m_selectedCommodities.Clear();

                    foreach (SQL.Datasets.dsEliteDB.tbcommodityRow dRow in m_Table.Select("is_selected = true"))
		                m_selectedCommodities.Add(dRow.id);
                }
                else if(DialogResult == System.Windows.Forms.DialogResult.Yes)
                {
                    DialogResult = System.Windows.Forms.DialogResult.OK;
                    m_selectedCommodities.Clear();
                }
                
                return this.DialogResult;
            }
            catch (Exception ex)
            {
                throw new Exception("Error while starting form", ex);
            }
        }
开发者ID:Duke-Jones,项目名称:ED-IBE,代码行数:28,代码来源:CommoditySelector.cs

示例8: Delete

        public bool Delete(Room value)
        {
            bool result = false;

            MachineHibernate machineHibernate = new MachineHibernate();
            result = machineHibernate.DeleteByRoom(value.Guid);

            DatabaseHibernate hibernate = new DatabaseHibernate();
            List<Parameter> parameters = new List<Parameter>();

            if (result)
            {
                string sql = string.Format("delete from e_user_room as t where [t].[room_id] = '{0}'", value.Guid);
                parameters.Clear();

                result = hibernate.Write(Variable.Link, sql, parameters);
            }

            if (result)
            {
                string sql = string.Format("delete from e_room as t where [t].[guid] = '{0}'", value.Guid);
                parameters.Clear();

                result = hibernate.Write(Variable.Link, sql, parameters);
            }

            return result;
        }
开发者ID:egretor,项目名称:EnvironmentalMonitor,代码行数:28,代码来源:RoomHibernate.cs

示例9: FindLongestSequence

        public static List<int> FindLongestSequence(List<int> numbers)
        {
            List<int> result = new List<int>();
            List<int> currentSequence = new List<int>();

            if (numbers.Count == 1)
            {
                return numbers;
            }

            int i = 0;
            while (i < numbers.Count - 1)
            {
                int j = i;
                currentSequence.Add(numbers[j]);
                while (j < numbers.Count-1 && numbers[j] == numbers[j + 1])
                {
                    currentSequence.Add(numbers[j + 1]);
                    j++;
                }
                if (currentSequence.Count > result.Count)
                {
                    result.Clear();
                    result.AddRange(currentSequence);
                    currentSequence.Clear();
                }
                else
                {
                    currentSequence.Clear();
                }
                i = j + 1;
            }

            return result;
        }
开发者ID:straho99,项目名称:Data-Structures---homeworks,代码行数:35,代码来源:LongestSequence.cs

示例10: LoadCharacters

        public void LoadCharacters(ContentManager myContentManager)
        {
            // ############## ALL THE INGAME CHARACTERS ARE DEFINED HERE ################

            // Dummy Player Char
            List<String> body = new List<String>();
            List<String> face = new List<String>();
            AddCharacter("Spieler", body, face, myContentManager);

            // Testy
            body.Clear();
            face.Clear();
            body.Add("testy_normal");
            body.Add("testy_angry");
            body.Add("testy_happy");
            body.Add("testy_shy");
            AddCharacter("Testy", body, face, myContentManager);

            // Blondie
            body.Clear();
            face.Clear();
            body.Add("blondie1");
            body.Add("blondie2");
            body.Add("blondie3");
            AddCharacter("Blondie", body, face, myContentManager);

            // Schwarz
            body.Clear();
            face.Clear();
            body.Add("schwarz1");
            body.Add("schwarz2");
            AddCharacter("Schwarz", body, face, myContentManager);
        }
开发者ID:HunterwolfAT,项目名称:CrashDate,代码行数:33,代码来源:CharacterManager.cs

示例11: MaxSequenceIncols

    static List<string> MaxSequenceIncols(string[,] matrix)
    {
        List<string> maxSequenceIncols = new List<string>();

        for (int i = 0; i < matrix.GetLength(1); i++)
        {
            List<string> currentSequence = new List<string>();
            currentSequence.Add(matrix[0, i]);
            for (int j = 1; j < matrix.GetLength(0); j++)
            {
                if (!currentSequence[0].Equals(matrix[j, i]))
                {
                    if (currentSequence.Count > maxSequenceIncols.Count)
                    {
                        maxSequenceIncols.Clear();
                        maxSequenceIncols = CopyList(maxSequenceIncols, currentSequence);
                    }
                    currentSequence.Clear();
                }
                currentSequence.Add(matrix[j, i]);
            }
            if (currentSequence.Count > maxSequenceIncols.Count)
            {
                maxSequenceIncols.Clear();
                maxSequenceIncols = CopyList(maxSequenceIncols, currentSequence);
            }
        }

        return maxSequenceIncols;
    }
开发者ID:KrasiNedew,项目名称:SoftUni,代码行数:30,代码来源:SequenceInMatrix.cs

示例12: Main

        static void Main(string[] args)
        {
            string ruleTypeName = ConfigurationSettings.AppSettings["RuleType"];
            Assembly assem = Assembly.Load("SalesTaxes.Items");
            ITaxedRule taxedRule = assem.CreateInstance(ruleTypeName) as ITaxedRule;
          
            List<AbstractItem> items = new List<AbstractItem>();
            items.Add(new Item(Category.BOOK, false, 12.49m));
            items.Add(new Item(Category.OTHERS, false, 14.99m));
            items.Add(new Item(Category.FOOD, false, 0.85m));

            PrintPrice(taxedRule.Apply(items));
            Console.WriteLine("--------------");

            items.Clear();
            items.Add(new Item(Category.FOOD, true, 10.00m));
            items.Add(new Item(Category.OTHERS, true, 47.50m));
            PrintPrice(taxedRule.Apply(items));
            Console.WriteLine("--------------");

            items.Clear();
            items.Add(new Item(Category.OTHERS, true, 27.99m));
            items.Add(new Item(Category.OTHERS, false, 18.99m));
            items.Add(new Item(Category.MEDICAL, false, 9.75m));
            items.Add(new Item(Category.FOOD, true, 11.25m));
            PrintPrice(taxedRule.Apply(items));
            Console.Read();
        }
开发者ID:linzhixiong,项目名称:.net,代码行数:28,代码来源:Program.cs

示例13: YieldDocuments

		private IEnumerable<IEnumerable<JsonDocument>> YieldDocuments()
		{
			var list = new List<JsonDocument>();
			while (true)
			{
				JsonDocument item;
				if (queue.TryTake(out item, 100) == false)
				{
					if (list.Count != 0)
					{
						ReportProgress(list);
						yield return list;
						list.Clear();
					}
					continue;
				}
				if (item == null) //marker
				{
					ReportProgress(list); 
					yield return list; 
					yield break;
				}

				list.Add(item);
				if (list.Count >= options.BatchSize)
				{
					ReportProgress(list); 
					yield return list;
					list.Clear();
				}
			}
		}
开发者ID:nberardi,项目名称:ravendb,代码行数:32,代码来源:EmbeddedBulkInsertOperation.cs

示例14: SetValue

        public static int SetValue(string strName, string strValue)
        {
            string sql = "SELECT value FROM Params WHERE [email protected];";
            List<SQLiteParameter> cmdParams = new List<SQLiteParameter>()
            {
                new SQLiteParameter("Name",strName),
            };
            DataTable dt = DBAdapter.Select(sql, cmdParams);
            if (dt == null)
                return -1;

            if (dt.Rows.Count <= 0)
            {
                sql = "INSERT INTO Params (name,value) VALUES (@Name,@Value);";
                cmdParams.Clear();
                cmdParams.Add(new SQLiteParameter("Name", strName));
                cmdParams.Add(new SQLiteParameter("Value", strValue));
                return DBAdapter.Execute(sql, cmdParams);
            }
            else
            {
                sql = "UPDATE Params SET [email protected] WHERE [email protected];";
                cmdParams.Clear();
                cmdParams.Add(new SQLiteParameter("Name", strName));
                cmdParams.Add(new SQLiteParameter("Value", strValue));
                return DBAdapter.Execute(sql, cmdParams);
            }
              
        }
开发者ID:jameshuang-i,项目名称:test,代码行数:29,代码来源:SysParam.cs

示例15: Main

        static void Main(string[] args)
        {
            for (int k = 0; k < 100; k++)
            {

                //tth
                int AWinCount = 0;
                int BWinCount = 0;

                var resultStack = new List<bool>();

                for (int i = 0; i < 1000; i++)
                {
                    bool coinResult = RandomGenerator.GetCoin();

                    resultStack.Add(coinResult);
                    if (AWin(resultStack))
                    {
                        AWinCount++;
                        resultStack.Clear();
                    }
                    else if (BWin(resultStack))
                    {
                        BWinCount++;
                        resultStack.Clear();
                    }

                }

                Console.WriteLine("A win {0}, B win {1}", AWinCount, BWinCount);
            }
        }
开发者ID:IamTonyZHOU,项目名称:Test,代码行数:32,代码来源:Program.cs


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