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


C# Collection.Remove方法代码示例

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


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

示例1: Main

 private static void Main()
 {
     ICollection<string> myCole = new Collection<string>(); //Initializing a collection of strings
     myCole.Add("Takane"); //Adding elements on a collection
     myCole.Add("Sena");
     myCole.Add("Masuzu");
     myCole.Add("Yusa Emi");
     foreach(string b in myCole){
         Console.WriteLine("myCole contains " + b);
     }
     myCole.Remove("Yusa Emi"); //removing an element on a collection
     Console.WriteLine("Deleted an element");
     bool a = myCole.Contains("Takane"); //tells whether the collection contains a certain element
     //enumerate the elements
     foreach(string b in myCole){
         Console.WriteLine("myCole contains " + b);
     }
     
     //copying the content of a collection to an array
     string[] c = new string[myCole.Count]; // initializes the array with the size equal to myCole
     myCole.CopyTo(c, 0); //Copy to string array c from element 0
     foreach(string d in c){
         Console.WriteLine("String Copy in c: {0}", d);
     }
 }
开发者ID:ChanahC,项目名称:CSharpTrain,代码行数:25,代码来源:CollectionTrial.cs

示例2: RemoveAttributes

 private void RemoveAttributes(Collection<CustomAttribute> customAttributes)
 {
     foreach (var customAttribute in customAttributes.Where(IsWeakEventAttribute).ToList())
     {
         customAttributes.Remove(customAttribute);
     }
 }
开发者ID:adbancroft,项目名称:WeakEvents.Fody,代码行数:7,代码来源:ModuleWeaver.cs

示例3: RemoveAttributes

        void RemoveAttributes(Collection<CustomAttribute> customAttributes)
        {
            var attributes = customAttributes
                .Where(attribute => _propertyAttributeNames.Contains(attribute.Constructor.DeclaringType.FullName));

            foreach (var customAttribute in attributes.ToList())
            {
                customAttributes.Remove(customAttribute);
            }
        }
开发者ID:brainoffline,项目名称:Commander.Fody,代码行数:10,代码来源:AttributeCleanerProcessor.cs

示例4: RemoveAttributes

    void RemoveAttributes(Collection<CustomAttribute> customAttributes, string fullName)
    {
        var attributes = customAttributes
            .Where(attribute => propertyAttributeNames.Contains(attribute.Constructor.DeclaringType.Name));

        foreach (var customAttribute in attributes.ToList())
        {
            logger.LogMessage(string.Format("\tRemoving attribute '{0}' from '{1}'.", customAttribute.Constructor.DeclaringType.FullName, fullName));
            customAttributes.Remove(customAttribute);
        }
    }
开发者ID:marcuswhit,项目名称:NotifyPropertyWeaver,代码行数:11,代码来源:AttributeCleaner.cs

示例5: FindPath

 public static List<Point> FindPath(int[,] field, Point start, Point goal)
 {
     //step 1
     var closedSet = new Collection<PathNode>();
     var openSet = new Collection<PathNode>();
     //step 2
     PathNode startNode = new PathNode()
     {
         Position = start,
         CameFrom = null,
         PathLengthFromStart = 0,
         HeuristicEstimatePathLength = GetHeuristicPathLength(start, goal)
     };
     openSet.Add(startNode);
     while (openSet.Count > 0)
     {
         //step 3
         var currentNode = openSet.OrderBy(node =>
           node.EstimateFullPathLength).First();
         //step 4.
         if (currentNode.Position == goal)
             return GetPathForNode(currentNode);
         //step 5.
         openSet.Remove(currentNode);
         closedSet.Add(currentNode);
         //step 6.
         foreach (var neighbourNode in GetNeighbours(currentNode, goal, field))
         {
             //step 7.
             if (closedSet.Count(node => node.Position == neighbourNode.Position) > 0)
                 continue;
             var openNode = openSet.FirstOrDefault(node =>
               node.Position == neighbourNode.Position);
             //step 8.
             if (openNode == null)
                 openSet.Add(neighbourNode);
             else
               if (openNode.PathLengthFromStart > neighbourNode.PathLengthFromStart)
             {
                 //step 9.
                 openNode.CameFrom = currentNode;
                 openNode.PathLengthFromStart = neighbourNode.PathLengthFromStart;
             }
         }
     }
     //step 10.
     return null;
 }
开发者ID:sword36,项目名称:town,代码行数:48,代码来源:PathNode.cs

示例6: AddWhenTimoutNotElapsedTest

        public void AddWhenTimoutNotElapsedTest()
        {
            var _objects = new Collection<object>();
            var _newObject = new object();

            Parallel.Invoke(
                () => _objects.Add(_newObject, 50, () => _objects.Remove(_newObject)),
                () =>
                {
                    Thread.Sleep(10);
                    Assert.IsTrue(_objects.Contains(_newObject));
                }
                );

            Assert.IsTrue(_objects.Contains(_newObject));
        }
开发者ID:ikyaqoob,项目名称:RabbitCache,代码行数:16,代码来源:CollectionExtensionTest.cs

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

示例8: FindPath

 public List<Cell> FindPath(GameField field, Cell start, Cell goal, Func<Cell, Cell, float> weightFunc = null)
 {
     var closedSet = new Collection<PathNode>();
     var openSet = new Collection<PathNode>();
     PathNode startNode = new PathNode()
     {
         Position = start,
         CameFrom = null,
         PathLengthFromStart = 0,
         HeuristicEstimatePathLength = GetHeuristicPathLength(start, goal)
     };
     openSet.Add(startNode);
     while (openSet.Count > 0)
     {
         var currentNode = openSet.OrderBy(node =>
           node.EstimateFullPathLength).First();
         if (currentNode.Position == goal)
             return GetPathForNode(currentNode);
         openSet.Remove(currentNode);
         closedSet.Add(currentNode);
         foreach (var neighbourNode in GetNeighbours(currentNode, goal, field, weightFunc))
         {
             if (closedSet.Count(node => node.Position == neighbourNode.Position) > 0)
                 continue;
             var openNode = openSet.FirstOrDefault(node =>
               node.Position == neighbourNode.Position);
             if (openNode == null)
                 openSet.Add(neighbourNode);
             else
                 if (openNode.PathLengthFromStart > neighbourNode.PathLengthFromStart)
                 {
                     openNode.CameFrom = currentNode;
                     openNode.PathLengthFromStart = neighbourNode.PathLengthFromStart;
                 }
         }
     }
     return null;
 }
开发者ID:temik911,项目名称:audio,代码行数:38,代码来源:AStar.cs

示例9: CreateTokenInfo

        /// <inheritdoc />
        public virtual TokenInfo CreateTokenInfo(IEnumerable<Claim> claims, TimeSpan? lifetime, string secretKey)
        {
            if (claims == null)
            {
                throw new ArgumentNullException("claims");
            }

            if (lifetime != null && lifetime < TimeSpan.Zero)
            {
                string msg = CommonResources.ArgMustBeGreaterThanOrEqualTo.FormatForUser(TimeSpan.Zero);
                throw new ArgumentOutOfRangeException("lifetime", lifetime, msg);
            }

            if (string.IsNullOrEmpty(secretKey))
            {
                throw new ArgumentNullException("secretKey");
            }

            // add the claims passed in
            Collection<Claim> finalClaims = new Collection<Claim>();
            foreach (Claim claim in claims)
            {
                finalClaims.Add(claim);
            }

            // add our standard claims
            finalClaims.Add(new Claim("ver", "3"));

            Claim uidClaim = finalClaims.SingleOrDefault(p => p.Type == ClaimTypes.NameIdentifier);
            if (uidClaim != null)
            {
                finalClaims.Remove(uidClaim);
                finalClaims.Add(new Claim("uid", uidClaim.Value));
            }

            return CreateTokenFromClaims(finalClaims, secretKey, ZumoAudienceValue, ZumoIssuerValue, lifetime);
        }
开发者ID:huoxudong125,项目名称:azure-mobile-apps-net-server,代码行数:38,代码来源:MobileAppTokenHandler.cs

示例10: ChangeTheme

        private static void ChangeTheme(Collection<ResourceDictionary> mergedDictionaries, ThemeTones tone, Color accentColor)
        {
            var metroDictionaries = mergedDictionaries.OfType<MetroDictionary>().ToArray();

            foreach (var d in metroDictionaries)
                mergedDictionaries.Remove(d);

            if (tone == ThemeTones.None)
                return;

            ResourceDictionary toneDictionary = null;

            switch (tone)
            {
                case ThemeTones.Light:
                    toneDictionary = GetThemeResourceDictionary("StyleLight");
                    break;
                case ThemeTones.Dark:
                    toneDictionary = GetThemeResourceDictionary("StyleDark");
                    break;
            }

            var accentDictionary = CreateAccentDictionary(accentColor);

            mergedDictionaries.Add(toneDictionary);

            mergedDictionaries.Add(accentDictionary);

            foreach (var s in StyleFiles)
            {
                var dict = GetThemeResourceDictionary(s);
                dict.MergedDictionaries.Add(toneDictionary);
                dict.MergedDictionaries.Add(accentDictionary);

                mergedDictionaries.Add(dict);
            }
        }
开发者ID:distantcam,项目名称:MetroChrome,代码行数:37,代码来源:ThemeManager.cs

示例11: AddCrossingPointToLine

        internal static Collection<FlagedVertex> AddCrossingPointToLine(LineShape line, Collection<PointShape> crossingPoints)
        {
            Collection<FlagedVertex> orderedPoints = new Collection<FlagedVertex>();
            for (int i = 0; i < line.Vertices.Count - 1; i++)
            {
                // Add the first vertex of segment.
                if (!HasExists(orderedPoints, line.Vertices[i]))
                {
                    orderedPoints.Add(new FlagedVertex() { Vertex = line.Vertices[i] , Flag = true});
                }

                Dictionary<PointShape, double> pointsOnSegement = new Dictionary<PointShape, double>();
                foreach (PointShape crossingPoint in crossingPoints)
                {
                    // Add the crossing point if it's on the segment.
                    bool isIntermiate = IsIntermediatePoint(line.Vertices[i], line.Vertices[i + 1], crossingPoint);
                    if (isIntermiate)
                    {
                        double pointDistance = GetEvaluatedDistance(line.Vertices[i], crossingPoint);
                        pointsOnSegement.Add(crossingPoint, pointDistance);
                    }
                }

                if (pointsOnSegement.Count > 0)
                {
                    pointsOnSegement.OrderBy(v => v.Value);
                    foreach (var pointOnSegment in pointsOnSegement)
                    {
                        Vertex vertex = new Vertex(pointOnSegment.Key.X, pointOnSegment.Key.Y);
                        if (!HasExists(orderedPoints, vertex))
                        {
                            bool isOnTheLine = false;
                            foreach (var item in line.Vertices)
                            {
                                if(vertex.X == item.X && vertex.Y == item.Y)
                                {
                                    isOnTheLine = true;
                                    break;
                                }
                            }

                            if(isOnTheLine)
                            {
                                orderedPoints.Add(new FlagedVertex() { Vertex = vertex, Flag = true });
                            }
                            else
                            {
                                orderedPoints.Add(new FlagedVertex() { Vertex = vertex, Flag = false });
                            }
                        }
                        crossingPoints.Remove(pointOnSegment.Key);
                    }
                }
            }

            if(line.Vertices.Count > orderedPoints.Count)
            {
                bool isLoop = false;
                foreach (var item in orderedPoints)
                {
                    if (line.Vertices[line.Vertices.Count - 1].X == item.Vertex.X && line.Vertices[line.Vertices.Count - 1].Y == item.Vertex.Y)
                    {
                        isLoop = true;
                        break;
                    }
                }

                if(isLoop)
                {
                    orderedPoints.Add(new FlagedVertex() { Vertex = new Vertex(line.Vertices[line.Vertices.Count - 1].X, line.Vertices[line.Vertices.Count - 1].Y), Flag = true });
                }
            }

            return orderedPoints;
        }
开发者ID:SCNU-R,项目名称:RoutingAlgorithm,代码行数:75,代码来源:GeometryHelper.cs

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

示例13: click_handler


//.........这里部分代码省略.........
                    title_value.Visible = false;
                    cdContent_teaser.Visible = false;
                    if (ex.Message.IndexOf("Invalid License") == 0)
                    {
                        title_label.Text = ex.Message.ToString();
                    }
                    else
                    {
                        title_label.Text = "You do not have rights to add content in FolderID=" + ModeID;
                    }
                }
                break;
            case CurrentMode.Edit:
                if (bWithLang == true)
                {
                    Ektron.Cms.Content.EkContent brContent;
                    Collection page_content_data = new Collection();

                    m_refContentApi.ContentLanguage = iOrigLang;
                    brContent = m_refContentApi.EkContentRef;
                    page_content_data = brContent.GetContentByIDv2_0(ModeID);
                    m_refContentApi.ContentLanguage = iNewLang;
                    brContent = m_refContentApi.EkContentRef;

                    if (m_SelectedEditControl.ToLower() == "jseditor")
                    {
                        strContent = Page.Server.HtmlDecode((string)(Page.Request.Form["EkInnerEditor"].ToString()));
                    }
                    else
                    {
                        strContent = (string)cdContent_teaser.Content;
                    }
                    strSearchText = Utilities.StripHTML(strContent);
                    page_content_data.Remove("ContentHtml");
                    strContent = Utilities.WikiQLink(strContent, Convert.ToInt64(page_content_data["FolderID"]));
                    page_content_data.Add(strContent, "ContentHtml", null, null);
                    page_content_data.Remove("ContentLanguage");
                    page_content_data.Add(iNewLang, "ContentLanguage", null, null);
                    if (page_content_data.Contains("ContentTeaser") && (page_content_data["ContentTeaser"].ToString() == ""))
                    {

                        strContentTeaser = Utilities.AutoSummary(strContent);

                        if (strContentTeaser != "")
                        {
                            strContentTeaser = "<p>" + strContentTeaser + "</p>";
                        }
                        page_content_data.Remove("ContentTeaser");
                        page_content_data.Add(strContentTeaser, "ContentTeaser", null, null);
                    }
                    else
                    {
                        if (auto_generate_summary.Checked == true)
                        {
                            // strContentTeaser = Utilities.WikiQLink(strContent, ModeID)
                            strContentTeaser = Utilities.AutoSummary(strContent);

                            if (strContentTeaser != "")
                            {
                                strContentTeaser = "<p>" + strContentTeaser + "</p>";
                            }
                            page_content_data.Remove("ContentTeaser");
                            page_content_data.Add(strContentTeaser, "ContentTeaser", null, null);
                        }
                    }
                    if (page_content_data.Contains("SearchText"))
开发者ID:jaytem,项目名称:minGit,代码行数:67,代码来源:membership_add_content.aspx.cs

示例14: ReadParameter

        private static ICollection<DataProperty> ReadParameter(ICollection<XElement> properties,
            ICollection<Parameter> parameters)
        {
            var proplist = new Collection<DataProperty>();
            var proplistError = new Collection<DataProperty>();

            foreach (var property in GetPropertyNodesWithSpecificType(properties, DataPropertyType.Parameter))
            {
                var prop = new DataProperty
                               {
                                   Id = XmlTools.GetNamedAttributeValue(property, "id", null),
                                   PropertyType = DataPropertyType.Parameter
                               };

                if (prop.Id == null)
                {
                    var msg = "Missing 'id' attribute in Property Node: '" + XmlTools.GetOuterXml(property) + "'";
                    Log.WriteError(msg, "ExtractProperties");
                    throw new InstallerVerificationLibraryException(msg);
                }

                var parameterId = XmlTools.GetNamedAttributeValue(property, "parameterID", null);
                if (!string.IsNullOrEmpty(parameterId))
                {
                    var found = false;
                    foreach (var parm in parameters.Where(parm => parm.Id == parameterId))
                    {
                        prop.Value = parm.Value;
                        proplist.Add(prop);
                        found = true;
                        break;
                    }

                    if (found)
                    {
                        //// If found delete if property exist in error list
                        if (proplistError.Contains(prop))
                        {
                            proplistError.Remove(prop);
                        }
                    }
                    else
                    {
                        //// If not found and it doesn't allready exist add property to error list
                        if (!proplist.Contains(prop))
                        {
                            prop.Value = XmlTools.GetOuterXml(property);
                            proplistError.Add(prop);
                        }
                    }
                }
                else
                {
                    var msg = "parameterID attribute is missing for property '" + XmlTools.GetOuterXml(property) + "'";
                    Log.WriteError(msg, "ExtractProperties");
                    throw new InstallerVerificationLibraryException(msg);
                }
            }

            //// Check if any error exist
            if (proplistError.Count > 0)
            {
                var msg = proplistError.Aggregate(string.Empty, (current, prop) => current + ("Property Node: '" + prop.Value + "' doesn't contain a valid parameterId"));

                Log.WriteError(msg, "ExtractProperties");
                throw new InstallerVerificationLibraryException(msg);
            }

            return proplist;
        }
开发者ID:pwibeck,项目名称:InstallerVerificationFramework,代码行数:70,代码来源:DataPropertyTool.cs

示例15: _RemoveUnassignedOrders

        /// <summary>
        /// Removes unassigned orders from collection.
        /// </summary>
        /// <param name="ordersToAssign">Dragged orders collection.</param>
        /// <param name="currentSchedule">Current schedule.</param>
        private void _RemoveUnassignedOrders(ref Collection<Order> ordersToAssign, Schedule currentSchedule)
        {
            Collection<Order> orders = new Collection<Order>();
            foreach (Order order in ordersToAssign)
            {
                if (currentSchedule.UnassignedOrders.Contains(order))
                    orders.Add(order);
            }

            foreach (Order order in orders)
                ordersToAssign.Remove(order);
        }
开发者ID:erindm,项目名称:route-planner-csharp,代码行数:17,代码来源:DropOrdersCmd.cs


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