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


C# Collection.Clear方法代码示例

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


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

示例1: ValidateTryParseAll

        public void ValidateTryParseAll()
        {
            IEnumerable<string> stringVals;
            Collection<string> strColl = new Collection<string>();
            strColl.Add("1"); strColl.Add("2"); 
            stringVals = strColl.OrderBy(a => a);
            IList<int> resultInt;
            Assert.IsTrue(Parser.TryParseAll(stringVals, out resultInt));
            Assert.AreEqual(1, resultInt.ElementAt(0));
            Assert.AreEqual(2, resultInt.ElementAt(1));

            strColl.Clear();
            strColl.Add("true"); strColl.Add("false");
            stringVals = strColl.OrderBy(a => a);
            IList<bool> resultBool;
            Assert.IsTrue(Parser.TryParseAll(stringVals, out resultBool));
            Assert.AreEqual(false, resultBool.ElementAt(0));
            Assert.AreEqual(true, resultBool.ElementAt(1));

            strColl.Clear();
            strColl.Add("1.23"); strColl.Add("7.98");
            stringVals = strColl.OrderBy(a => a);
            IList<float> resultFloat;
            Assert.IsTrue(Parser.TryParseAll(stringVals, out resultFloat));
            Assert.AreEqual(1.23f, resultFloat.ElementAt(0));
            Assert.AreEqual(7.98f, resultFloat.ElementAt(1));
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:27,代码来源:ParserBvtTestCases.cs

示例2: getUser

        public static Collection<Utilisateur> getUser()
        {
            Collection<Utilisateur> mesUsers = new Collection<Utilisateur>();

            try
            {
                mesUsers.Clear();
                bdd.GestBiblioNetConn.Open();

                String SQL = "SELECT * FROM Utilisateur";

                MySqlDataReader MonReaderUtilisateur;
                MySqlCommand Command1 = new MySqlCommand(SQL, bdd.GestBiblioNetConn);
                MonReaderUtilisateur = Command1.ExecuteReader();

                Utilisateur nouveauUser;
                while (MonReaderUtilisateur.Read())
                {
                    nouveauUser = new Utilisateur(int.Parse(MonReaderUtilisateur[0].ToString()), MonReaderUtilisateur[1].ToString(), MonReaderUtilisateur[2].ToString(), MonReaderUtilisateur[3].ToString(), MonReaderUtilisateur[4].ToString(), MonReaderUtilisateur[5].ToString(), MonReaderUtilisateur[6].ToString(), MonReaderUtilisateur[7].ToString());
                    nouveauUser.MesCommandesUser = M_Commande.getCommandesUser(nouveauUser);
                    mesUsers.Add(nouveauUser);
                }

                bdd.GestBiblioNetConn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erreur : " + ex.Message);
            }

            return mesUsers;
        }
开发者ID:AlfaBrisingr,项目名称:BiblioNetBO,代码行数:32,代码来源:M_Utilisateur.cs

示例3: ShuffleList

        public static string[] ShuffleList(string[] list)
        {
            if (list.Length <= 1)
                return list;

            // Convert list to collection
            Collection<string> collection = new Collection<string>();
            foreach (string str in list)
            {
                collection.Add(str);
            }

            string[] randomList = new string[collection.Count];

            Random r = new Random(DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Millisecond);
            int randomIndex = 0;
            int currentIndex = 0;
            while (collection.Count > 0)
            {
                randomIndex = r.Next(0, collection.Count); //Choose a random object in the list
                randomList[currentIndex++] = collection[randomIndex]; //add it to the new, random list<
                collection.RemoveAt(randomIndex); //remove to avoid duplicates
            }

            //clean up
            collection.Clear();
            collection = null;
            r = null;

            return randomList; //return the new random list
        }
开发者ID:pabitrad,项目名称:Projects,代码行数:31,代码来源:ArrayUtilities.cs

示例4: readString

        public async static void readString(ProcessStartInfo start)
        {




            Process p = new Process();
            p.StartInfo = start;
            p.EnableRaisingEvents = true;
            p.Exited += new EventHandler(OnProcessExit);
            p.Start();
            StreamReader q = p.StandardOutput;
            int count = 0;
            Collection<EventData> e = new Collection<EventData>();
            while (!p.HasExited) {
                count++;
                string x = q.ReadLine();
               

                if (true) //bulksend
                {
                    if (count >= 100)
                    {
                      
                        SendingBulkMessage(e);
                        count = 0;
                        e.Clear();
                    }
                    else
                    {
                        if (count % 2 == 0)
                        {
                            e.Add(new EventData(Encoding.UTF8.GetBytes(x)));
                            Console.WriteLine(count);
                        }
                       
                    }
                }
                else {
                    if (count % 5 == 0)
                    {
                        SendingMessage(q);
                        Console.WriteLine(count);
                    }
                  
                }


                //GC.Collect();
            }
            Console.ReadKey();
            //p.BeginErrorReadLine();
        }
开发者ID:tanchunsiong,项目名称:Custom-Connect-The-Dots---Public,代码行数:53,代码来源:Program.cs

示例5: getCategories

        public static Collection<Categories> getCategories()
        {
            Collection<Categories> CollectionCategorie = new Collection<Categories>();

            try
            {
                CollectionCategorie.Clear();

                // Ouverture de la connexion
                M_Connexion.Gestion.Open();

                // Requête SQL
                String ReqSQL = "SELECT * FROM categorie";

                // Déclaration du curseur
                MySqlDataReader MonReaderCategorie;

                // Execution de la requête
                MySqlCommand Command1 = new MySqlCommand(ReqSQL, M_Connexion.Gestion);
                MonReaderCategorie = Command1.ExecuteReader();

                Categories uneCategories;

                while (MonReaderCategorie.Read())
                {
                    uneCategories = new Categories(int.Parse(MonReaderCategorie[0].ToString()), MonReaderCategorie[1].ToString());
                    CollectionCategorie.Add(uneCategories);
                }
                // Fermeture de la connexion
                M_Connexion.Gestion.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erreur :" + ex.Message);
                M_Connexion.Gestion.Close();
            }

            return CollectionCategorie;
        }
开发者ID:Mansikkapoika,项目名称:Musichall-Logiciel,代码行数:39,代码来源:M_Categories.cs

示例6: Run

        public static void Run()
        {
            Collection<string> dinosaurs = new Collection<string>();

            dinosaurs.Add("Psitticosaurus");
            dinosaurs.Add("Caudipteryx");
            dinosaurs.Add("Compsohnathus");
            dinosaurs.Add("Muttaburrasaurus");

            Console.WriteLine("{0} dinosaurs:", dinosaurs.Count);
            Display(dinosaurs);

            Console.WriteLine("\nIndexOf(\"Muttaburrasaurus\"): {0}", dinosaurs.IndexOf("Muttaburrasaurus"));

            Console.WriteLine("\nContains(\"Caudipteryx\"): {0}",  dinosaurs.Contains("Caudipteryx"));

            Console.WriteLine("\nInsert(2, \"Nanotyrannus\")");
            dinosaurs.Insert(2, "Nanotyrannus");
            Display(dinosaurs);

            Console.WriteLine("\ndinosaurs[2]: {0}", dinosaurs[2]);

            Console.WriteLine("\ndinosaurs[2] = \"Microraptor\"");
            dinosaurs[2] = "Microraptor";
            Display(dinosaurs);

            Console.WriteLine("\nRemove(\"Microraptor\")");
            dinosaurs.Remove("Microraptor");
            Display(dinosaurs);

            Console.WriteLine("\nRemoveAt(0)");
            dinosaurs.RemoveAt(0);
            Display(dinosaurs);

            Console.WriteLine("\ndinosaurs.Clear()");
            dinosaurs.Clear();
            Console.WriteLine("Count: {0}", dinosaurs.Count);
        }
开发者ID:oblivious,项目名称:Oblivious,代码行数:38,代码来源:CollectionGeneric.cs

示例7: getFournisseurs

        public static Collection<Fournisseurs> getFournisseurs()
        {
            Collection<Fournisseurs> CollectionFournisseur = new Collection<Fournisseurs>();

            try
            {
                CollectionFournisseur.Clear();

                // Ouverture de la connexion
                M_connexion.Gestion.Open();

                // Requête SQL
                String ReqSQL = "SELECT * FROM Fournisseurs";

                // Déclaration du curseur
                MySqlDataReader MonReaderFournisseur;

                // Execution de la requête
                MySqlCommand Command1 = new MySqlCommand(ReqSQL, M_connexion.Gestion);
                MonReaderFournisseur = Command1.ExecuteReader();

                Fournisseurs unFournisseur;

                while (MonReaderFournisseur.Read())
                {
                    unFournisseur = new Fournisseurs(int.Parse(MonReaderFournisseur[0].ToString()), MonReaderFournisseur[1].ToString());
                    CollectionFournisseur.Add(unFournisseur);
                }
                // Fermeture de la connexion
                M_connexion.Gestion.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erreur :" + ex.Message);
            }

            return CollectionFournisseur;
        }
开发者ID:Rodaxfck,项目名称:Stage_BO-Gestionstock-2e-annee,代码行数:38,代码来源:M_fournisseurs.cs

示例8: Parse

        /// <summary>
        /// Parse words to intermediate phrase.
        /// </summary>
        /// <param name="intermediateWords">Words to be parsed.</param>
        public void Parse(Collection<ScriptWord> intermediateWords)
        {
            ProsodicWords.Clear();
            Collection<ScriptWord> words = new Collection<ScriptWord>();
            for (int i = 0; i < intermediateWords.Count; i++)
            {
                ScriptWord word = intermediateWords[i];

                // Append non-normal word to the intermediate break phrase.
                words.Add(word);
                if (word.IsPronouncableNormalWord &&
                    (word.Break >= TtsBreak.Word ||
                    intermediateWords.IndexOf(word) == (intermediateWords.Count - 1)))
                {
                    for (int j = i + 1; j < intermediateWords.Count; j++)
                    {
                        if (intermediateWords[j].IsPronouncableNormalWord)
                        {
                            break;
                        }
                        else
                        {
                            words.Add(intermediateWords[j]);
                            i = j;
                        }
                    }

                    ScriptProsodicWord prosodicWord = new ScriptProsodicWord()
                    {
                        IntermediatePhrase = this,
                    };

                    Helper.AppendCollection<ScriptWord>(prosodicWord.Words, words);
                    ProsodicWords.Add(prosodicWord);
                    words.Clear();
                }
            }

            if (words.Count > 0)
            {
                ScriptProsodicWord prosodicWord = new ScriptProsodicWord()
                {
                    IntermediatePhrase = this,
                };

                Helper.AppendCollection<ScriptWord>(prosodicWord.Words, words);
                ProsodicWords.Add(prosodicWord);
                words.Clear();
            }
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:54,代码来源:ScriptIntermediatePhrase.cs

示例9: TestAdd

        public void TestAdd()
        {
            var rand = new Random(3);

            ListCollection<string> list1 = new ListCollection<string>();
            Collection<string> list2 = new Collection<string>();

            //Check Add
            for (int x = 0; x < 100; x++)
            {
                var str = x.ToString();
                list1.Add(str);
                list2.Add(str);

                CheckEquals1(list1, list2);
            }

            //Check Remove
            for (int x = 100; x < 200; x++)
            {
                var str = x.ToString();
                var removeItem = list1[rand.Next(list1.Count)];
                list1.Remove(removeItem);
                list2.Remove(removeItem);

                CheckEquals1(list1, list2);

                list1.Add(str);
                list2.Add(str);

                CheckEquals1(list1, list2);
            }

            //Check RemoveAt
            for (int x = 0; x < 100; x++)
            {
                int index = rand.Next(list1.Count);
                list1.RemoveAt(index);
                list2.RemoveAt(index);

                CheckEquals1(list1, list2);
            }

            //Check Insert
            for (int x = 0; x < 100; x++)
            {
                int index = rand.Next(list1.Count);
                list1.Insert(index, x.ToString());
                list2.Insert(index, x.ToString());

                CheckEquals1(list1, list2);
            }

            //Check set
            for (int x = 0; x < 100; x++)
            {
                int index = rand.Next(list1.Count);
                list1[index] = x.ToString();
                list2[index] = x.ToString();

                CheckEquals1(list1, list2);
            }

            list1.Clear();
            list2.Clear();
            CheckEquals1(list1, list2);

            //Check Add
            for (int x = 0; x < 100; x++)
            {
                var str = x.ToString();
                list1.Add(str);
                list2.Add(str);

                CheckEquals1(list1, list2);
            }

            //Check indexOf
            for (int x = 0; x < 100; x++)
            {
                int index = rand.Next(list1.Count * 2);

                if (list1.IndexOf(index.ToString()) != list2.IndexOf(index.ToString()))
                    throw new Exception();

                CheckEquals1(list1, list2);
            }

            string[] lst1 = new string[list1.Count];
            string[] lst2 = new string[list2.Count];

            list1.CopyTo(lst1, 0);
            list2.CopyTo(lst2, 0);

            CheckEquals3(list1, list2);

            for (int x = 0; x < 100; x++)
            {
                int index = rand.Next(list1.Count * 2);

//.........这里部分代码省略.........
开发者ID:GridProtectionAlliance,项目名称:gsf,代码行数:101,代码来源:ListCollectionTests.cs

示例10: CloseAndClearCommandSessions

        // closes all the active command sessions.
        private void CloseAndClearCommandSessions(
            Exception reasonForClose)
        {
            Collection<WSManPluginCommandSession> copyCmdSessions = new Collection<WSManPluginCommandSession>();
            lock (shellSyncObject)
            {
                Dictionary<IntPtr, WSManPluginCommandSession>.Enumerator cmdEnumerator = _activeCommandSessions.GetEnumerator();
                while (cmdEnumerator.MoveNext())
                {
                    copyCmdSessions.Add(cmdEnumerator.Current.Value);
                }

                _activeCommandSessions.Clear();
            }

            // close the command sessions outside of the lock
            IEnumerator<WSManPluginCommandSession> cmdSessionEnumerator = copyCmdSessions.GetEnumerator();
            while (cmdSessionEnumerator.MoveNext())
            {
                WSManPluginCommandSession cmdSession = cmdSessionEnumerator.Current;
                // we are not interested in session closed events anymore as we are initiating the close
                // anyway/
                cmdSession.SessionClosed -= new EventHandler<EventArgs>(this.HandleCommandSessionClosed);
                cmdSession.Close(reasonForClose);
            }
            copyCmdSessions.Clear();
        }
开发者ID:40a,项目名称:PowerShell,代码行数:28,代码来源:WSManPluginShellSession.cs

示例11: Calculate

        private Collection<Edge> Calculate(string[] nodeNames)
        {
            Collection<Edge> resultEdges = new Collection<Edge>();

            Node targetNode = this.nodes.FirstOrDefault(n => n.Name == nodeNames[0]);
            if (targetNode != null)
            {
                for (int i = 1; i < nodeNames.Length; i++)
                {
                    Edge targetEdge = targetNode.Edges.FirstOrDefault(ed => ed.End == nodeNames[i]);
                    if (targetEdge != null)
                    {
                        resultEdges.Add(targetEdge);
                        targetNode = this.nodes.FirstOrDefault(n => n.Name == nodeNames[i]);
                        if (targetNode != null)
                        {
                            continue;
                        }
                        else
                        {
                            Console.WriteLine("Cannot find.");
                            resultEdges.Clear();
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Cannot find.");
                        resultEdges.Clear();
                        break;
                    }
                }
            }

            return resultEdges;
        }
开发者ID:schooloffish,项目名称:TransRoutes,代码行数:36,代码来源:Graph.cs

示例12: GetAccounts

        public static Collection<AccountInfo> GetAccounts(string groupname)
        {
            try
            {
                XmlDocument objXmlDoc = GetGroupConfigFile(groupname);
                if (objXmlDoc == null)
                    return null;

                DataView dv = GetData(objXmlDoc, Constants.CONFIG_ROOT + Constants.CHAR_SLASH + Constants.ACCOUNT_ACCOUNTS);

                Collection<AccountInfo> accounts = new Collection<AccountInfo>();
                accounts.Clear();

                for (int ix = 0; ix < dv.Table.Rows.Count; ix++)
                {
                    AccountInfo account = new AccountInfo();
                    account.Email = dv.Table.Rows[ix][0].ToString();
                    account.Password = dv.Table.Rows[ix][1].ToString();
                    account.UserName = dv.Table.Rows[ix][2].ToString();
                    account.UserId = dv.Table.Rows[ix][3].ToString();
                    account.Gender = DataConvert.GetBool(dv.Table.Rows[ix][4]);
                    accounts.Add(account);
                }

                return accounts;
            }
            catch (Exception ex)
            {
                LogHelper.Write("读取组内账号" + groupname, ex);
                return null;
            }
        }
开发者ID:jojozhuang,项目名称:Projects,代码行数:32,代码来源:ConfigCtrl.cs

示例13: ParseVersions

        /// <summary>
        /// Parse version node list.
        /// </summary>
        /// <param name="versionsNodeList">Versions node list.</param>
        /// <param name="nsmgr">Xml namespace manager.</param>
        /// <param name="versions">Version collection.</param>
        public static void ParseVersions(XmlNodeList versionsNodeList,
            XmlNamespaceManager nsmgr, Collection<FontVersion> versions)
        {
            if (versionsNodeList == null)
            {
                throw new ArgumentNullException("versionsNodeList");
            }

            if (nsmgr == null)
            {
                throw new ArgumentNullException("nsmgr");
            }

            if (versions == null)
            {
                throw new ArgumentNullException("versions");
            }

            versions.Clear();
            foreach (XmlNode node in versionsNodeList)
            {
                XmlElement ele = (XmlElement)node;
                FontVersion fv = new FontVersion();

                fv.CompressCatalog = (WaveCompressCatalog)Enum.Parse(typeof(WaveCompressCatalog),
                    ele.GetAttribute("compress"));
                fv.PcmCategory = (WaveFormatTag)Enum.Parse(typeof(WaveFormatTag),
                    ele.GetAttribute("encoding"));
                fv.SamplesPerSecond = int.Parse(ele.GetAttribute("samplesPerSecond"),
                    CultureInfo.InvariantCulture);
                fv.BytesPerSample = int.Parse(ele.GetAttribute("bytesPerSample"),
                    CultureInfo.InvariantCulture);
                fv.Name = ele.GetAttribute("name");

                try
                {
                    fv.Validate();
                }
                catch (NotSupportedException nse)
                {
                    string message = string.Format(CultureInfo.InvariantCulture,
                        "Not support version config found {0}.",
                        ele.OuterXml);
                    throw new InvalidDataException(message, nse);
                }

                versions.Add(fv);
            }
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:55,代码来源:FontCompilerConfig.cs

示例14: Parse

     // parse the CSV file
 internal Collection<RepairOrder> Parse(Stream stream)
 {
     var items = new Collection<RepairOrder>();
     int max = _MaxPreview;
     int ret = max;
     if (_ShowAll | 0 == max)
     {
         max = 0;
     }
     else
     {
         max = _MaxPreview + 1;
     }
     CSV file = new CSV(stream, 
         hasHeaders: true, charDelimiter:',', charQuote:'"', charEscapeQuote:'\\', fileEncoding:Encoding.UTF8, maxRecords:max, name:Title);
     DataTable table = file.ToDataTable();
     if (null == table)
     {
         _Proxy.NoticeLog(string.Format("EBS Bulk Import cannot parse file {0} id {1}. Cannot create data table.", 
             Title, FileId), null);
         _JobStatus = JobStatus.ParseError;
         stream.Dispose();
         items.Clear();
         return items;
     }
     stream.Dispose();
     DataRowCollection rows = table.Rows;
     int rowCount = rows.Count;
     ret = rowCount;
     if (0 == rowCount || (rowCount <= _MaxPreview) || (0 == max))
     {
         _LoadedAll = true;
         IsShowAllEnabled = false;
     }
     else if (rowCount == (_MaxPreview + 1))
     {
         _LoadedAll = false;
         IsShowAllEnabled = true;
         ret = rowCount - 1;
     }
     else
     {
         _LoadedAll = false;
         IsShowAllEnabled = true;
     }
     int i = 0;
     foreach (DataRow row in rows)
     {
         if (++i > ret)
         {
             break;
         }
         var item = new RepairOrder(
                 this,
                 this._Model.EbsSrId,
                 Convert.ToString(row.Field<object>("PROBLEM_DESCRIPTION")),
                 0,
                 Convert.ToString(row.Field<object>("APPROVAL_REQUIRED_FLAG")),
                 Convert.ToDecimal(row.Field<object>("REPAIR_TYPE_ID")),
                 Convert.ToDecimal(row.Field<object>("QUANTITY")),
                 Convert.ToString(row.Field<object>("UNIT_OF_MEASURE")),
                 Convert.ToString(row.Field<object>("CURRENCY_CODE")),
                 0
             );
         item.SerialNumber = Convert.ToString(row.Field<object>("SERIAL_NUMBER"));                
         items.Add(item);
     }
     return items;
 }
开发者ID:oo00spy00oo,项目名称:Accelerators,代码行数:70,代码来源:ImportFile.cs

示例15: Merge

 private void Merge(DeepCopier copier, Collection<Instruction>def1, Collection<Instruction> def2)
 {
     //TODO dont override destination instructions always, we migth gona need prepend
     def2.Clear();
     foreach(var i in def1){
         def2.Add(copier.Copy(i));
     }
 }
开发者ID:tritao,项目名称:flood,代码行数:8,代码来源:TypeWeaver.cs


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