Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
should arraylist converted into stringbuilder arraylist having multiple values i need to put all in string builder
C#
StringBuilder arrayvalues = new StringBuilder();
            try
            {
                foreach (object o in arr)
                {
                    arrayvalues.Append(o.ToString());
                }
            }


its possible to do
Posted
Comments
kashif Atiq 31-Jan-12 5:26am    
ya its possible

C#
StringBuilder arrayvalues = new StringBuilder();
            try
            {
                foreach (var o in arr)
                {
                    arrayvalues.Append(o.ToString());
                }
            }
 
Share this answer
 
Comments
Sibasisjena 31-Jan-12 5:31am    
it is another way i have written above
yes why not if don't work just do a little change like this
and u have to use "using System.Text;"
C#
StringBuilder arrayvalues = new StringBuilder();
            try
            {
                foreach (object o in arr)
                {
                    arrayvalues = arrayvalues.Append(o.ToString());
                }
            }
 
Share this answer
 
v3
Don't use ArrayList, use System.Windows.Collections.Generic.List, http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx[^].

Non-generic classes were rendered obsolete in the .NET Framework v.2.0, when generics were introduced. They are still used in legacy code (and ware not formally marked with Obsolete attribute to avoid breaking of backward compatibility), but in new development they make no sense and bad because they require type cast.

Also, consider review of the code design to use StringBuilder in first place. The solutions using foreach are correct though.

—SA
 
Share this answer
 

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