本文整理汇总了C#中Hashtable.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# Hashtable.GetEnumerator方法的具体用法?C# Hashtable.GetEnumerator怎么用?C# Hashtable.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hashtable
的用法示例。
在下文中一共展示了Hashtable.GetEnumerator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
Hashtable artists = new Hashtable();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("../../../albums.xml");
string xPathQuery = "/albums/album/artist";
XmlNodeList artistsList = xmlDoc.SelectNodes(xPathQuery);
foreach (XmlNode artistNode in artistsList)
{
string artistName = artistNode.InnerText;
if (artists.ContainsKey(artistName))
{
artists[artistName] = (int) artists[artistName] + 1;
}
else
{
artists.Add(artistName, 1);
}
}
var artistsEnumerator = artists.GetEnumerator();
while (artistsEnumerator.MoveNext())
{
Console.WriteLine(artistsEnumerator.Key + " " + artistsEnumerator.Value);
}
}
示例2: Main
static void Main()
{
Hashtable artists = new Hashtable();
XmlDocument doc = new XmlDocument();
doc.Load("../../../albums.xml");
XmlNode rootNode = doc.DocumentElement;
foreach (XmlNode album in rootNode.ChildNodes)
{
string artistName = album["artist"].InnerText;
if (artists.ContainsKey(artistName))
{
artists[artistName] = (int)artists[artistName] + 1;
}
else
{
artists.Add(artistName, 1);
}
}
var artistsEnumerator = artists.GetEnumerator();
while (artistsEnumerator.MoveNext())
{
Console.WriteLine(artistsEnumerator.Key + " " + artistsEnumerator.Value);
}
}
示例3: printMap
public static void printMap(Hashtable map)
{
IDictionaryEnumerator keys = map.GetEnumerator();
while (keys.MoveNext())
{
Console.Out.WriteLine("*KEY* " + keys.Key + ", *OBJECT* " + keys.Value);
}
}
示例4: h_get_Value
public static object h_get_Value(Hashtable h, String Key)
{
IDictionaryEnumerator c = h.GetEnumerator();
while (c.MoveNext())
{
while ((c.Key.ToString()) == Key) return c.Value;
}
return "nodata";
}
示例5: Main
public static void Main()
{
Hashtable permi = new Hashtable();
permi["hola"] = true;
string despedida = "adios";
permi[despedida] = false;
Console.WriteLine("hola {0}", permi["hola"]);
IDictionaryEnumerator enumerador = permi.GetEnumerator();
while (enumerador.MoveNext())
Console.WriteLine("\t{0}:\t{1}", enumerador.Key, enumerador.Value);
}
示例6: writeHeaders
private void writeHeaders(Hashtable<String, String> headers)
{
if (headers != null && headers.size() > 0)
{
Hashtable<String, String>.Enumerator hashEnum = headers.GetEnumerator();
while( hashEnum.MoveNext() )
{
String strName = hashEnum.Current.Key;
String strValue = hashEnum.Current.Value;
m_webRequest.Headers[strName] = strValue;
}
}
}
示例7: GetMissingHandlers
public static string GetMissingHandlers(Hashtable EventList)
{
StringBuilder Handlers = new StringBuilder();
IDictionaryEnumerator myEnumerator = EventList.GetEnumerator();
while ( myEnumerator.MoveNext() )
{
EventHandlerItem i = (EventHandlerItem) myEnumerator.Value;
if (!i.Found)
{
Handlers.AppendFormat("\tpublic void {0} (object sender, EventArgs a)\n\t{1}\n\t//TODO: Add your code here.\n\t{2}\n\n",i.Handler,'{','}');
}
}
return Handlers.ToString();
}
示例8: writeHeaders
private void writeHeaders(Hashtable<String, String> headers)
{
if (headers != null && headers.size() > 0)
{
Hashtable<String, String>.Enumerator hashEnum = headers.GetEnumerator();
while( hashEnum.MoveNext() )
{
String strName = hashEnum.Current.Key;
String strValue = hashEnum.Current.Value;
m_webRequest.Headers[strName.Replace("-", "")] = strValue;
}
}
m_webRequest.UserAgent = "rhodes-wp7";
}
示例9: Emit
public void Emit(Hashtable actions,string actvars,bool nameSpace,bool showDfa)
{
if (showDfa)
{
for (int j=0;j<states.Count; j++)
((Dfa)states[j]).Print();
foreach (DictionaryEntry d in m_tokens.starts)
Console.WriteLine((string)d.Key+": "+((Dfa)d.Value).m_state);
}
m_outFile.WriteLine("//%|"+m_outname);
m_outFile.WriteLine("public class yy"+m_outname+" : YyLexer {");
m_outFile.WriteLine(" public yy"+m_outname+"(ErrorHandler eh):base(eh) { arr = new int[] { ");
m_tokens.EmitDfa(m_outFile);
foreach(string x in m_tokens.tokens.Keys)
m_outFile.WriteLine(" new Tfactory(this,\""+x+"\",new TCreator("+x+"_factory));");
m_outFile.WriteLine("}");
foreach (string y in m_tokens.tokens.Keys)
m_outFile.WriteLine("public static object "+y+"_factory(Lexer yyl) { return new "+y+"(yyl);}");
Console.WriteLine("Actions function");
m_outFile.WriteLine("public override TOKEN OldAction(Lexer yym,ref string yytext,int action, ref bool reject) {");
m_outFile.WriteLine(" switch(action) {");
m_outFile.WriteLine(" case -1: break;");
IDictionaryEnumerator pos = actions.GetEnumerator();
for (int m=0;m<actions.Count;m++)
{
pos.MoveNext();
int act = (int)pos.Key;
NfaNode e = (NfaNode)pos.Value;
if (e.m_sTerminal.Length!=0 && e.m_sTerminal[0]=='%') // auto token action
continue;
m_outFile.WriteLine(" case {0}: {1}",act,ActionTransform(e.m_sTerminal));
m_outFile.WriteLine(" break;"); // in case m_sTerminal ends with a // comment (quite likely)
}
m_outFile.WriteLine(" }");
m_outFile.WriteLine(" return null;");
m_outFile.WriteLine("}}");
m_outFile.WriteLine("public class "+m_outname+":Lexer {");
m_outFile.WriteLine("public "+m_outname+"():base(new yy"+m_outname+"(new ErrorHandler(false))) {}");
m_outFile.WriteLine("public "+m_outname+"(ErrorHandler eh):base(new yy"+m_outname+"(eh)) {}");
m_outFile.WriteLine("public "+m_outname+"(YyLexer tks):base(tks){}");
m_outFile.WriteLine(actvars);
m_outFile.WriteLine(" }");
if (nameSpace)
m_outFile.WriteLine("}");
}
示例10: TestSynchronizedBasic
public void TestSynchronizedBasic()
{
Hashtable hsh1;
string strValue;
Task[] workers;
Action ts1;
int iNumberOfWorkers = 3;
DictionaryEntry[] strValueArr;
string[] strKeyArr;
Hashtable hsh3;
Hashtable hsh4;
IDictionaryEnumerator idic;
object oValue;
//[]Vanila - Syncronized returns a wrapped HT. We must make sure that all the methods
//are accounted for here for the wrapper
hsh1 = new Hashtable();
for (int i = 0; i < _iNumberOfElements; i++)
{
hsh1.Add("Key_" + i, "Value_" + i);
}
_hsh2 = Hashtable.Synchronized(hsh1);
//Count
Assert.Equal(_hsh2.Count, hsh1.Count);
//get/set item
for (int i = 0; i < _iNumberOfElements; i++)
{
Assert.True(((string)_hsh2["Key_" + i]).Equals("Value_" + i));
}
Assert.Throws<ArgumentNullException>(() =>
{
oValue = _hsh2[null];
});
_hsh2.Clear();
for (int i = 0; i < _iNumberOfElements; i++)
{
_hsh2["Key_" + i] = "Value_" + i;
}
strValueArr = new DictionaryEntry[_hsh2.Count];
_hsh2.CopyTo(strValueArr, 0);
//ContainsXXX
hsh3 = new Hashtable();
for (int i = 0; i < _iNumberOfElements; i++)
{
Assert.True(_hsh2.Contains("Key_" + i));
Assert.True(_hsh2.ContainsKey("Key_" + i));
Assert.True(_hsh2.ContainsValue("Value_" + i));
//we still need a way to make sure that there are all these unique values here -see below code for that
Assert.True(hsh1.ContainsValue(((DictionaryEntry)strValueArr[i]).Value));
hsh3.Add(strValueArr[i], null);
}
hsh4 = (Hashtable)_hsh2.Clone();
Assert.Equal(hsh4.Count, hsh1.Count);
strValueArr = new DictionaryEntry[hsh4.Count];
hsh4.CopyTo(strValueArr, 0);
//ContainsXXX
hsh3 = new Hashtable();
for (int i = 0; i < _iNumberOfElements; i++)
{
Assert.True(hsh4.Contains("Key_" + i));
Assert.True(hsh4.ContainsKey("Key_" + i));
Assert.True(hsh4.ContainsValue("Value_" + i));
//we still need a way to make sure that there are all these unique values here -see below code for that
Assert.True(hsh1.ContainsValue(((DictionaryEntry)strValueArr[i]).Value));
hsh3.Add(((DictionaryEntry)strValueArr[i]).Value, null);
}
Assert.False(hsh4.IsReadOnly);
Assert.True(hsh4.IsSynchronized);
//Phew, back to other methods
idic = _hsh2.GetEnumerator();
hsh3 = new Hashtable();
hsh4 = new Hashtable();
while (idic.MoveNext())
{
Assert.True(_hsh2.ContainsKey(idic.Key));
Assert.True(_hsh2.ContainsValue(idic.Value));
hsh3.Add(idic.Key, null);
hsh4.Add(idic.Value, null);
}
hsh4 = (Hashtable)_hsh2.Clone();
strValueArr = new DictionaryEntry[hsh4.Count];
hsh4.CopyTo(strValueArr, 0);
hsh3 = new Hashtable();
//.........这里部分代码省略.........
示例11: ScanFileForEventHandlers
public static void ScanFileForEventHandlers(string FileName,Hashtable EventList)
{
System.IO.StreamReader sr = new System.IO.StreamReader(FileName);
string line;
while ((line = sr.ReadLine()) != null)
{
IDictionaryEnumerator myEnumerator = EventList.GetEnumerator();
while ( myEnumerator.MoveNext() )
{
EventHandlerItem i = (EventHandlerItem) myEnumerator.Value;
//Todo: A nice Regex to detect EventHandlers would be a good idea.
if ( (line.IndexOf(i.Handler) != -1) && (line.IndexOf("void") != -1) )
{
i.Found=true;
}
}
}
sr.Close();
}
示例12: EXIFextractorEnumerator
internal EXIFextractorEnumerator( Hashtable exif )
{
this.exifTable = exif;
this.Reset();
index = exif.GetEnumerator();
}
示例13: runTest
private Boolean runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
ArrayList alst = null;
ArrayList tst = null;
IList ilst1 = null;
IList ilst2 = null;
String strLoc = null;
Hashtable hsh1 = null;
IDictionaryEnumerator idic = null;
try
{
strLoc = "Loc_04872dsf";
iCountTestcases++;
alst = new ArrayList();
tst = ArrayList.Adapter(alst);
hsh1 = new Hashtable();
CompareObjects(alst, tst, hsh1);
iCountTestcases++;
if(hsh1.Count>2
|| ((String)hsh1["Capacity"] != "get")
|| ((String)hsh1["TrimToSize"] != "Monekeyed, 301 301")
)
{
iCountErrors++;
Console.WriteLine("Err_742dsf! Adapter");
idic = hsh1.GetEnumerator();
while(idic.MoveNext())
{
Console.WriteLine("<" + idic.Key + "><" + idic.Value + ">");
}
}
strLoc = "Loc_210742wdsfg";
iCountTestcases++;
alst = new ArrayList();
for(int i=0; i<100;i++)
alst.Add(i);
tst = ArrayList.Adapter(alst);
hsh1 = new Hashtable();
CompareObjects(alst, tst, hsh1);
if(hsh1.Count>2
|| ((String)hsh1["Capacity"] != "get")
|| ((String)hsh1["TrimToSize"] != "Monekeyed, 301 301")
)
{
iCountErrors++;
Console.WriteLine("Err_75629ewf! Adapter");
idic = hsh1.GetEnumerator();
while(idic.MoveNext())
{
Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
}
}
strLoc = "Loc_6927csf";
iCountTestcases++;
alst = new ArrayList();
tst = ArrayList.FixedSize(alst);
hsh1 = new Hashtable();
CompareObjects(alst, tst, hsh1);
if(hsh1.Count>1 || !hsh1.ContainsKey("Fixed"))
{
iCountErrors++;
Console.WriteLine("Err_0371dsf! Adapter");
idic = hsh1.GetEnumerator();
while(idic.MoveNext())
{
Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
}
}
strLoc = "Loc_79231";
alst = new ArrayList();
for(int i=0; i<100;i++)
alst.Add(i);
tst = ArrayList.FixedSize(alst);
hsh1 = new Hashtable();
CompareObjects(alst, tst, hsh1);
iCountTestcases++;
if(hsh1.Count>1 || !hsh1.ContainsKey("Fixed"))
{
iCountErrors++;
Console.WriteLine("Err_8427efs! Adapter");
idic = hsh1.GetEnumerator();
while(idic.MoveNext())
{
Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
}
}
strLoc = "Loc_6792dsf";
iCountTestcases++;
ilst1 = new ArrayList();
ilst2 = ArrayList.FixedSize(ilst1);
hsh1 = new Hashtable();
DoIListTests(ilst1, ilst2, hsh1);
if(hsh1.Count>1 || !hsh1.ContainsKey("Fixed"))
{
iCountErrors++;
Console.WriteLine("Err_127we! FixedSize, IList");
idic = hsh1.GetEnumerator();
//.........这里部分代码省略.........
示例14: TestGetSyncRootBasic
public void TestGetSyncRootBasic()
{
Hashtable arrSon;
Hashtable arrMother;
Task[] workers;
Action ts1;
Action ts2;
Int32 iNumberOfWorkers = 30;
Hashtable hshPossibleValues;
IDictionaryEnumerator idic;
Hashtable hsh1;
Hashtable hsh2;
Hashtable hsh3;
//[] we will create different HT and make sure that they return different SyncRoot values
hsh1 = new Hashtable();
hsh2 = new Hashtable();
Assert.NotEqual(hsh1.SyncRoot, hsh2.SyncRoot);
Assert.Equal(hsh1.SyncRoot.GetType(), typeof(object));
//[] a clone of a Syncronized HT should not be pointing to the same SyncRoot
hsh1 = new Hashtable();
hsh2 = Hashtable.Synchronized(hsh1);
hsh3 = (Hashtable)hsh2.Clone();
Assert.NotEqual(hsh2.SyncRoot, hsh3.SyncRoot);
Assert.NotEqual(hsh1.SyncRoot, hsh3.SyncRoot);
//[] testing SyncRoot is not as simple as its implementation looks like. This is the working
//scenrio we have in mind.
//1) Create your Down to earth mother Hashtable
//2) Get a synchronized wrapper from it
//3) Get a Synchronized wrapper from 2)
//4) Get a synchronized wrapper of the mother from 1)
//5) all of these should SyncRoot to the mother earth
arrMother = new Hashtable();
for (int i = 0; i < _iNumberOfElements; i++)
{
arrMother.Add("Key_" + i, "Value_" + i);
}
arrSon = Hashtable.Synchronized(arrMother);
_arrGrandDaughter = Hashtable.Synchronized(arrSon);
_arrDaughter = Hashtable.Synchronized(arrMother);
Assert.Equal(arrSon.SyncRoot, arrMother.SyncRoot);
Assert.Equal(arrSon.SyncRoot, arrMother.SyncRoot);
Assert.Equal(_arrGrandDaughter.SyncRoot, arrMother.SyncRoot);
Assert.Equal(_arrDaughter.SyncRoot, arrMother.SyncRoot);
Assert.Equal(arrSon.SyncRoot, arrMother.SyncRoot);
//we are going to rumble with the Hashtables with some threads
workers = new Task[iNumberOfWorkers];
ts2 = new Action(RemoveElements);
for (int iThreads = 0; iThreads < iNumberOfWorkers; iThreads += 2)
{
var name = "Thread_worker_" + iThreads;
ts1 = new Action(() => AddMoreElements(name));
workers[iThreads] = Task.Run(ts1);
workers[iThreads + 1] = Task.Run(ts2);
}
Task.WaitAll(workers);
//checking time
//Now lets see how this is done.
//Either there should be some elements (the new ones we added and/or the original ones) or none
hshPossibleValues = new Hashtable();
for (int i = 0; i < _iNumberOfElements; i++)
{
hshPossibleValues.Add("Key_" + i, "Value_" + i);
}
for (int i = 0; i < iNumberOfWorkers; i++)
{
hshPossibleValues.Add("Key_Thread_worker_" + i, "Thread_worker_" + i);
}
idic = arrMother.GetEnumerator();
while (idic.MoveNext())
{
Assert.True(hshPossibleValues.ContainsKey(idic.Key), "Error, Expected value not returned, " + idic.Key);
Assert.True(hshPossibleValues.ContainsValue(idic.Value), "Error, Expected value not returned, " + idic.Value);
}
}
示例15: serializeObject
protected static bool serializeObject(Hashtable anObject, StringBuilder builder)
{
builder.Append("{");
IDictionaryEnumerator enumerator = anObject.GetEnumerator();
for (bool flag = true; enumerator.MoveNext(); flag = false)
{
string aString = enumerator.Key.ToString();
object obj2 = enumerator.Value;
if (!flag)
{
builder.Append(", ");
}
serializeString(aString, builder);
builder.Append(":");
if (!serializeValue(obj2, builder))
{
return false;
}
}
builder.Append("}");
return true;
}