02.List Generic Collection

Source: Internet
Author: User

List generics can be converted to an array
The same point for list generics and arrays: The data type of the list generic must be specified, and the data type of the array must also be specified. List generics and the difference between arrays: the length of the list generic is arbitrary, and the length of the array must be specified at the time of declaration.
Because the type of the list generic collection is unique, the list generic collection can be converted to an array of arrays. The list generic collection can be converted to what type of the set depends on what type of List generic collection is.
Most common methods for list generic collections and ArrayList are consistent. The list generic collection sample code:
  
 
  1. namespace _09.List泛型集合
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. //创建泛型集合对象
  8. List<int> list = new List<int>(); //创建了一个整型的泛型集合
  9. list.Add(1);
  10. list.Add(2);
  11. list.Add(3);
  12. list addrange ( new int Span class= "pun" >[] { 4 5 6 7 8 9 0
  13. foreach (var item in list)
  14. {
  15. Console.WriteLine(item);
  16. }
  17. Console.WriteLine("====================================");
  18. //将List泛型集合转换成数组
  19. int[] lArray=list.ToArray();
  20. for (int i = 0; i < lArray.Length; i++)
  21. {
  22. Console.WriteLine(lArray[i]);
  23. }
  24. Console.WriteLine("====================================");
  25. //将整型数组转换成泛型集合
  26. List<int> listTwo=lArray.ToList();
  27. for (int i = 0; i < listTwo.Count; i++)
  28. {
  29. Console.WriteLine(listTwo[i]);
  30. }
  31. Console.ReadKey();
  32. }
  33. }
  34. }




From for notes (Wiz)

02.List Generic Collection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.