Click here to Skip to main content
15,895,462 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi

C#
for(int j=0;j<dt.Rows.Count;j++)
            {
                al.Add(Convert.ToInt16(dt.Rows[j].ToString().Substring(3,dt.Rows[j].ToString().Length-3)));
            }
 List<int> list = al.Cast<int>().ToList();


when convert it gives casting error.
Posted
Updated 4-Feb-15 21:23pm
v3
Comments
nagendrathecoder 5-Feb-15 3:14am    
Have you looked in google?
BillWoodruff 5-Feb-15 12:05pm    
Without knowing what Types are in the ArrayList, it's hard to consider the best strategy.

C#
List<int> list = arrayList.Cast<int>().ToList();

if you have non integers in the array but still want integer list then try with
C#
List<int> integers = arrayList.OfType<int>().ToList();

or you items directly to a List of integers as below
C#
 List<int> list = new List<int>();
for(int j=0;j<dt.Rows.Count;j++)
            {
                list .Add(Convert.ToInt16(dt.Rows[j].ToString().Substring(3,dt.Rows[j].ToString().Length-3)));
            }
 
Share this answer
 
v4
Comments
basurajkumbhar 5-Feb-15 4:21am    
Thanks for reply

I have tried all of this but in the integers it dosen't give any count
ref : www.dotnetperls.com/convert-arraylist-list
 
Share this answer
 
for(int j=0;j<dt.rows.count;j++)>
            {
                al.Add(Convert.ToInt16(dt.Rows[j].ToString().Substring(3,dt.Rows[j].ToString().Length-3)));
	 list.Add(Convert.ToInt16(dt.Rows[j].ToString().Substring(3, dt.Rows[j].ToString().Length - 3)));
            }


i add that data table value in list and solve my problem..


Thanks for every body
 
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