.


:




:

































 

 

 

 


.




IDictionaryEnumerator , , Entry, Key Value, Current. , IDictionaryEnumerator, MoveNext (), . MoveNext (). false, .

Hashtable IDictionaryEnumerator.

// IDictionaryEnumerator.

Using System;

Using System.Collections;

class IDicEnumDemo { static void Main() {

// -.

Hashtable ht = new Hashtable();

// , ht.Add("", "555-7756"); ht.Add("", "555-9876"); ht.Add("", "555-3456"); ht.Add("", "555-3452");

// .

IDictionaryEnumerator etr = ht.GetEnumerator();

Console.WriteLine(" Entry."); while(etF.MoveNext())

Console.WriteLine(etr.Entry.Key + ": " + etr.Entry.Value);

Console.WriteLine();

Console.WriteLine(" " +

" Key Value.");

Etr.Reset ();

While(etr.MoveNext ())

Console.WriteLine(etr.Key + ": " + etr.Value);

}

}

.

Entry.

: 555-9876 : 555-3456 : 555-3452 : 555-7756

Key Value.

: 555-9876 : 555-3456 : 555-3452 : 555-7756

IEnumerable IEnumerator

, ( ) foreach, IEnumerator. : , , foreach, IEnumerator IEnumerable. , foreach, IEnumerator IEnumerable . , , .

IEnumerator IEnumerable , , MyClass.

Using System;

Using System.Collections;

class MyClass: IEnumerator, IEnumerable {

char[] chrs = { '', '', 'C', 'D' };

int idx = -1;

// IEnumerable. public IEnumerator GetEnumerator() {

Return this;

}

// IEnumerator

// , public object Current { get {

return chrs[idx];

}

}

// , public bool MoveNext() { if(idx == chrs.Length-1) {

Reset(); // return false;

}

idx++;

f

Return true;

}

// , public void Reset() { idx = -1; }

}

class EnumeratorlmplDemo { static void Main() {

MyClass me = new MyClass();

// me. foreach(char ch in me)

Console.Write (ch + 11 11);

Console.WriteLine();

// me. foreach(char ch in me)

Console.Write (ch + 11 ");

Console.WriteLine();

}

}

.

D D

MyClass, char, -D. idx, -1. MyClass , IEnumerator IEnumerable. GetEnumerator () , . Current , .. , idx. MoveNext () idx . false, , true. , MoveNext (). , MoveNext () foreach Current. idx - 1. foreach. .





:


: 2016-12-03; !; : 376 |


:

:

, .
==> ...

1480 - | 1392 -


© 2015-2024 lektsii.org - -

: 0.012 .