Click here to Skip to main content
15,908,775 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys I want your help, so java has the Enumeration class and more specifically it has a boolean method is the class that allows you to check if the Enumeration contains element.


Java
public String extractSelectAllValue(Hashtable pDataTable) {
Enumeration lKeyEnumeration;
String lKeyValue;
String lDataValue;
lKeyValue = "";
lDataValue = "";
try {
	lKeyEnumeration = pDataTable.keys();
	while(lKeyEnumeration.hasMoreElements()) {
	lKeyValue = (String)lKeyEnumeration.nextElement();
	lDataValue =  lDataValue +(String)pDataTable.get(lKeyValue) + "::";
    }
	return lDataValue;
    } catch(Exception e) {
      System.out.println("Error Extracting all Values of the list");
      e.printStackTrace();
      return "";
    }
	}


you get the idea, I wanted to know if c# has something like that. Because I have already checked the Enum class and I did not find any method that mirrors that.

Thanks for your help.
Posted
Updated 3-Oct-13 3:37am
v2

If your are using Hashtables the in c# you can do this :
C#
Hashtable hashtable = new Hashtable();
foreach (var key in hashtable.Keys)
{
    object o = hashtable[key]; // value of the key
    // do your stuff here
}
 
Share this answer
 
C# also contains the Enumaration class.Please check out the below code.
C#
using System;
using System.Collections;

public virtual string extractSelectAllValue(Hashtable pDataTable)
{
System.Collections.IEnumerator lKeyEnumeration;
string lKeyValue;
string lDataValue;
lKeyValue = "";
lDataValue = "";
try
{
    lKeyEnumeration = pDataTable.Keys.GetEnumerator();
    while (lKeyEnumeration.hasMoreElements())
    {
    lKeyValue = (string)lKeyEnumeration.nextElement();
    lDataValue = lDataValue + (string)pDataTable[lKeyValue] + "::";
    }
    return lDataValue;
}
catch(Exception ex)
{
throw ex;
}
 
Share this answer
 
Comments
rudolph098 7-Oct-13 9:43am    
Its complaining about 2 methods in the code. One being the hasMoreElements() and the nextElement().

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900