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


C# Map.Remove方法代码示例

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


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

示例1: AddOneDeleteOne

 public void AddOneDeleteOne()
 {
     Map<int,string> t = new Map<int,string>();
     t.Add(1, "one");
     t.Remove(1);
     Assert.AreEqual("" ,Dump(t));
     Assert.IsTrue(t.Count == 0);
 }
开发者ID:nemerle,项目名称:reko,代码行数:8,代码来源:MapTests.cs

示例2: Install

 public override void Install()
 {
     RouteList = new Map<IPAddress, Route>();
     Controller.RouteDiscovered += (s, e) =>
                                   {
                                       Route existing = RouteList.Where(p => p.Value.Network == e.Route.Network).OrderByDescending(p => p.Value.Mask.GetBitCount()).FirstOrDefault().Value;
                                       if (existing == null)
                                       {
                                           RouteList.Add(e.Route.Network, e.Route);
                                           Log.Write("SYSTEM", "RIB", "Add: " + e.Route.Network);
                                       }
                                       else
                                       {
                                           if (e.Route.Mask.GetBitCount() > existing.Mask.GetBitCount())
                                           {
                                               //++ most specific mask means different network; so AD isn't even a competitor for it
                                               RouteList[e.Route.Network] = e.Route;
                                               Log.Write("SYSTEM", "RIB", "Replaced via bit count: " + e.Route.Network);
                                           }
                                           else if (e.Route.AdministrativeDistance > RouteList[e.Route.Network].AdministrativeDistance)
                                           {
                                               //++ new AD is better? OK
                                               RouteList[e.Route.Network] = e.Route;
                                               Log.Write("SYSTEM", "RIB", "Replaced via AD: " + e.Route.Network);
                                           }
                                       }
                                   };
     Controller.RouteRemoved += (s, e) =>
                                {
                                    if (!RouteList.ContainsKey(e.Route.Network))
                                    {
                                        return;
                                    }
                                    RouteList.Remove(e.Route.Network);
                                    Log.Write("SYSTEM", "RIB", "Removed: " + e.Route.Network);
                                };
 }
开发者ID:davidbetz,项目名称:netrouter,代码行数:37,代码来源:SystemModule.cs

示例3: Main

        static void Main(string[] args)
        {
            Console.WriteLine("---LinkedList test---");

            var list = new LinkedList<string>();
            list.Add("x");
            list.Add("g");
            list.Add("s");

            Console.WriteLine(list.Count); //output: 3

            list.InsertAfter("g", "a");
            list.InsertBefore("g", "a");
            Console.WriteLine(list.InsertAt(10, "z")); //output: False
            list.InsertAt(2, "z");
            list.Remove("z");
            list[1] = "m";

            foreach (string value in list)
            {
                Console.WriteLine(value);
            }
            //output:
            //x
            //m
            //g
            //a
            //s

            Console.WriteLine("---DynamicArray test---");

            var dArray = new DynamicArray<string>();
            dArray.Add("x");
            dArray.Add("g");
            dArray.Add("s");

            Console.WriteLine(dArray.Count); //output: 3

            dArray.InsertAt(1, "a");
            dArray.InsertAt(3, "a");
            Console.WriteLine(dArray.InsertAt(10, "z")); //output: False
            dArray.InsertAt(2, "z");
            dArray.Remove("z");
            dArray[1] = "m";

            for (int i = 0; i < dArray.Count; i++)
            {
                Console.WriteLine(dArray[i]);
            }
            //output:
            //x
            //m
            //g
            //a
            //s

            Console.WriteLine("---Map test---");

            var map = new Map<int, string>();

            map.Add(1, "a");
            map.Add(2, "a");
            map.Add(3, "s");

            Console.WriteLine(map.Count); //output: 3

            try
            {
                map.Add(2, "v");
            }
            catch (ArgumentException argEx)
            {
                Console.WriteLine(argEx.Message); //exception message
            }

            Console.WriteLine(map.ContainsKey(2)); //output: True
            Console.WriteLine(map.ContainsValue("a")); //output: True
            map.Remove(2);
            Console.WriteLine(map.ContainsKey(2)); //output: False
            Console.WriteLine(map.ContainsValue("a")); //output: True

            Console.WriteLine(map.Count); //output: 2

            Console.WriteLine("---Hash Map test---");

            var hashMap = new Map<int, string>();

            hashMap.Add(1, "a");
            hashMap.Add(2, "a");
            hashMap.Add(3, "s");

            Console.WriteLine(hashMap.Count); //output: 3

            try
            {
                hashMap.Add(2, "v");
            }
            catch (ArgumentException argEx)
            {
                Console.WriteLine(argEx.Message); //exception message
//.........这里部分代码省略.........
开发者ID:abdonkov,项目名称:HackBulgaria-CSharp,代码行数:101,代码来源:Program.cs

示例4: AddThreeDeleteOne

 public void AddThreeDeleteOne()
 {
     Map<int,string> t = new Map<int,string>();
     t.Add(1, "one");
     t.Add(2, "two");
     t.Add(3, "three");
     Assert.IsTrue(t.Count == 3);
     Assert.IsTrue("one two three " == Dump(t));
     t.Remove(2);
     Assert.IsTrue(t.Count == 2);
     Assert.IsTrue("one three " == Dump(t));
 }
开发者ID:nemerle,项目名称:reko,代码行数:12,代码来源:MapTests.cs

示例5: DeleteTest

        public void DeleteTest()
        {
            Map<int,string> t = new Map<int,string>();
            t.Add(0, "0");
            t.Add(10, "10");
            t.Add(-10, "-10");
            t.Add(-5, "-5");
            t.Add(-7, "-7");
            string s = Dump(t);

            t.Remove(10);			// 10 should be black, so this forces a rebalance.
        }
开发者ID:nemerle,项目名称:reko,代码行数:12,代码来源:MapTests.cs


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