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


C# Collection.GetEnumerator方法代码示例

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


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

示例1: GetEnumerator

		public IEnumerator GetEnumerator ()
		{
			var instructions = new Collection<Instruction> ();
			Instruction instruction = _firstInstruction;
			while (true) {
				instructions.Add (instruction);
				if (instruction == _lastInstruction) break;
				instruction = instruction.Next;
			}
			return instructions.GetEnumerator ();
		}
开发者ID:transformersprimeabcxyz,项目名称:cecil-old,代码行数:11,代码来源:InstructionBlock.cs

示例2: Main

    public static void Main () {
        Collection<string> collection = new Collection<string> {
            "a",
            "b"
        };

        foreach (var s in collection) {
            Console.WriteLine(s);
        }

        Console.WriteLine(collection.Count);

        var test = collection.GetEnumerator();
    }
开发者ID:GlennSandoval,项目名称:JSIL,代码行数:14,代码来源:Issue585.cs

示例3: Case2

        /// <summary>
        /// 泛型实现
        /// 优点:一个集合可以适应多个不同的对象
        /// </summary>
        static void Case2()
        {
            Collection<Item> items = new Collection<Item> 
            { 
                new Item{Name="aa", Size=10},
                new Item{Name="bb", Size=20}
            };

            //foreach (Item item in items)
            //{
            //    Console.WriteLine(item.Name);
            //}

            IEnumerator<Item> enumerator = items.GetEnumerator();
            while (enumerator.MoveNext())
            {
                Console.WriteLine(enumerator.Current.Name);
            }
        }
开发者ID:0iron0,项目名称:Simon.Pattern.Demo,代码行数:23,代码来源:IteratorDemo.cs

示例4: CheckEquals2

        void CheckEquals2(Collection<string> list1, Collection<string> list2)
        {
            if (list1.Count != list2.Count)
                throw new Exception();
            for (int x = 0; x < list1.Count; x++)
            {
                if (list1[x] != list2[x])
                    throw new Exception();
            }

            var enum1 = list1.GetEnumerator();
            var enum2 = list2.GetEnumerator();

            while (enum1.MoveNext())
            {
                if (!enum2.MoveNext())
                    throw new Exception();

                if (enum1.Current != enum2.Current)
                    throw new Exception();
            }
            if (enum2.MoveNext())
                throw new Exception();

            CheckEquals3(list1, list2);

        }
开发者ID:GridProtectionAlliance,项目名称:gsf,代码行数:27,代码来源:ListCollectionTests.cs

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

示例6: setServices

        public void setServices(Collection col)
        {
            services = new ArrayList();
            prioritizedServices = new PrioritizedList();

            IEnumerator i = col.GetEnumerator();
            while (i.MoveNext()) {
                Service s = (Service)i.Current;
                addService(s);
            }
        }
开发者ID:AArnott,项目名称:dotnetxri,代码行数:11,代码来源:XRD.cs

示例7: setSelectedServices

 public void setSelectedServices(Collection svcs)
 {
     selectedServices = new PrioritizedList();
     IEnumerator i = svcs.GetEnumerator();
     while (i.MoveNext()) {
         Service s = (Service)i.Current;
         int? priority = s.getPriority();
         string priStr = (priority == null) ? "null" : priority.ToString();
         selectedServices.addObject(priStr, s);
     }
 }
开发者ID:AArnott,项目名称:dotnetxri,代码行数:11,代码来源:XRD.cs

示例8: setRefs

        public void setRefs(Collection col)
        {
            refs = new ArrayList();

            IEnumerator i = col.GetEnumerator();
            while (i.MoveNext()) {
                Ref r = (Ref)i.Current;
                addRef(r);
            }
        }
开发者ID:AArnott,项目名称:dotnetxri,代码行数:10,代码来源:XRD.cs

示例9: setEquivIDs

        public void setEquivIDs(Collection col)
        {
            equivIDs = new ArrayList();

            IEnumerator i = col.GetEnumerator();
            while (i.MoveNext()) {
                EquivID e = (EquivID)i.Current;
                addEquivID(e);
            }
        }
开发者ID:AArnott,项目名称:dotnetxri,代码行数:10,代码来源:XRD.cs

示例10: AtLeastOneHelpMessageIsPresent

		private static bool AtLeastOneHelpMessageIsPresent(Collection<FieldDescription> descriptions)
		{
			bool flag;
			IEnumerator<FieldDescription> enumerator = descriptions.GetEnumerator();
			using (enumerator)
			{
				while (enumerator.MoveNext())
				{
					FieldDescription current = enumerator.Current;
					if (current == null || string.IsNullOrEmpty(current.HelpMessage))
					{
						continue;
					}
					flag = true;
					return flag;
				}
				return false;
			}
			return flag;
		}
开发者ID:nickchal,项目名称:pash,代码行数:20,代码来源:ConsoleHostUserInterface.cs

示例11: HandleTimerElapsed

		private void HandleTimerElapsed(object sender, ElapsedEventArgs e)
		{
			Collection<string> strs = null;
			Collection<Connection> connections = null;
			Connection connection = null;
			ConcurrentDictionary<Guid, Connection> guids = null;
			ConcurrentDictionary<string, ConcurrentDictionary<Guid, Connection>> strs1 = null;
			if (Interlocked.CompareExchange(ref this._timerFired, 1, 0) != 1)
			{
				this._tracer.WriteMessage("PSW ConnMgr: Timer fired");
				this._servicingThreadRelease.WaitOne();
				this._timerThreadRelease.Reset();
				this._tracer.WriteMessage("PSW ConnMgr: Timer servicing started");
				Collection<string> strs2 = new Collection<string>();
				foreach (string str in strs)
				{
					ConcurrentDictionary<string, ConcurrentDictionary<Guid, Connection>> item = this._connectionPool[str];
					strs = new Collection<string>();
					foreach (string str1 in connections)
					{
						ConcurrentDictionary<Guid, Connection> item1 = item[str1];
						connections = new Collection<Connection>();
						lock (this._syncObject)
						{
							foreach (Connection value in item1.Values)
							{
								if (!value.Idle)
								{
									if (value.Busy)
									{
										continue;
									}
									value.Idle = true;
								}
								else
								{
									connections.Add(value);
								}
							}
						}
						IEnumerator<Connection> enumerator = connections.GetEnumerator();
						using (enumerator)
						{
							while (enumerator.MoveNext())
							{
								Connection connection1 = str1;
								ConnectionManager connectionManager = this;
								connectionManager._createdConnections = connectionManager._createdConnections - 1;
								item1.TryRemove(connection1.InstanceId, out connection);
								object[] computerName = new object[1];
								computerName[0] = connection1.Runspace.ConnectionInfo.ComputerName;
								this._tracer.WriteMessage(string.Format(CultureInfo.InvariantCulture, "Closing idle connection to {0}", computerName));
								this.SubmitOperation(new CloseOperation(connection1));
							}
						}
						if (item1.Count != 0)
						{
							continue;
						}
						strs.Add(str1);
					}
					IEnumerator<string> enumerator1 = strs.GetEnumerator();
					using (enumerator1)
					{
						while (enumerator1.MoveNext())
						{
							string str2 = str;
							item.TryRemove(str2, out guids);
						}
					}
					if (item.Keys.Count != 0)
					{
						continue;
					}
					strs2.Add(str);
				}
				foreach (string str3 in strs2)
				{
					this._connectionPool.TryRemove(str3, out strs1);
				}
				this._tracer.WriteMessage("PSW ConnMgr: Timer servicing completed");
				Interlocked.CompareExchange(ref this._timerFired, 0, 1);
				this._timerThreadRelease.Set();
				this.CheckAndStartRequiredThreads();
				return;
			}
			else
			{
				this._tracer.WriteMessage("PSW ConnMgr: Another timer thread is already servicing return");
				return;
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:92,代码来源:ConnectionManager.cs


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