Click here to Skip to main content
15,921,250 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i m working asp.net project. i had taken class its return type is arraylist and class return arrylist with multiple values now i want use all values from arrylist so
i send mail in mail i want all value in single pls suggest me
Posted
Comments
Herman<T>.Instance 31-Jan-12 4:02am    
maybe it is better to show your code.

The just concatenate the values, e.g.
C#
ArrayList al = new ArrayList();
al.Add(5);
al.Add("foo");
al.Add(true);
string s="";
foreach (object o in al)
{
  s += o.ToString();
}


If you have many items please consider using the StringBuilder[^] class.
 
Share this answer
 
 
Share this answer
 
Hi,

You can find generic solution for your case on internet.

Here is what I found:
C#
public static class ExtensionMethods 
{     
	// for generic interface IEnumerable<t>     
	public static string ToString<t>(this IEnumerable<t> source, string separator)     
	{         
		if (source == null)             
			throw new ArgumentException("Parameter source can not be null.");         

		if (string.IsNullOrEmpty(separator))             
			throw new ArgumentException("Parameter separator can not be null or empty.");         

		string[] array = source.Where(n => n != null).Select(n => n.ToString()).ToArray();         
		return string.Join(separator, array);
	}     

	// for interface IEnumerable     
	public static string ToString(this IEnumerable source, string separator)     
	{         
		if (source == null)             
			throw new ArgumentException("Parameter source can not be null.");         

		if (string.IsNullOrEmpty(separator))             
			throw new ArgumentException("Parameter separator can not be null or empty.");

		string[] array = source.Cast<object>().Where(n => n != null).Select(n => n.ToString()).ToArray();
		return string.Join(separator, array);    
	} 
}
</t></t></t>

Example of using this extension method:
C#
ArrayList myArrayList = new ArrayList();
myArrayList.Add("Item1");
myArrayList.Add("Item2");
myArrayList.Add("Item3");
myArrayList.Add("Item4");
myArrayList.Add("Item5");
	
string myListAsString = myArrayList.ToString("; ");


Output:
Item1; Item2; Item3; Item4; Item5
 
Share this answer
 
C#
ArrayList list = new ArrayList();

// Add ypur values to the array list

foreach (string s in list)
	{
	   // Here "s" contains a perticular value from the array list 
	}
 
Share this answer
 
v2
Comments
Anuja Pawar Indore 1-Feb-12 5:11am    
Added pre tag
Used code like this
C#
System.Collections.ArrayList arrList = new System.Collections.ArrayList()
        arrList.Add("1");
        arrList.Add("2");
        arrList.Add("3");

        for (int i=0;i < arrList.Count - 1;i++)
        {
              Response.Write(arrList(i).ToString() + "<br>")
        }
 
Share this answer
 
v2

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