code_junkie

Specifying the type of ArrayList's elements

Nov 11th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.21 KB | None | 0 0
  1. using System.Collections.Generic;
  2.  
  3. var list = new List<int>();
  4. list.Add(1);
  5. list.Add("string"); //compile-time error!
  6. int i = list[0];
  7.  
  8. string[] stringArray = myArrayList.ToArray(typeof(string)) as string[];
Add Comment
Please, Sign In to add comment