本文整理汇总了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 ();
}
示例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();
}
示例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);
}
}
示例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);
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例8: setRefs
public void setRefs(Collection col)
{
refs = new ArrayList();
IEnumerator i = col.GetEnumerator();
while (i.MoveNext()) {
Ref r = (Ref)i.Current;
addRef(r);
}
}
示例9: setEquivIDs
public void setEquivIDs(Collection col)
{
equivIDs = new ArrayList();
IEnumerator i = col.GetEnumerator();
while (i.MoveNext()) {
EquivID e = (EquivID)i.Current;
addEquivID(e);
}
}
示例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;
}
示例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;
}
}