0
点赞
收藏
分享

微信扫一扫

C#基础 List ToArray List转换为数组

慎壹 2023-04-20 阅读 59


  • .NET Framework : 4.7.2
  •        IDE : Visual Studio Community 2019
  •         OS : Windows 10 x64
  •     typesetting : Markdown
  •         blog : xinshaopu.blog.csdn.net

code

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = new List<int>();
            // 插入元素
            list.Add(1);
            // 插入数组
            list.AddRange(new int[] { 1, 2, 3, 4 });

            // 集合转为数组
            int[] nums = list.ToArray();
            foreach (var item in nums)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();

            // 数组转为集合
            int[] nums2 = new int[] { 22, 33, 44 };
            List<int> newList = nums2.ToList();
            foreach (var item in newList)
            {
                Console.WriteLine(item);
            }

            Console.ReadKey();
        }
    }
}

result

1
1
2
3
4

22
33
44

resource

  • [文档] docs.microsoft.com/zh-cn/dotnet/csharp
  • [规范] github.com/dotnet/docs/tree/master/docs/standard/design-guidelines
  • [源码] referencesource.microsoft.com
  • [ IDE ] visualstudio.microsoft.com/zh-hans
  • [.NET Core] dotnet.github.io

感恩曾经帮助过 心少朴 的人。
C#优秀,值得学习。.NET Core具有跨平台的能力,值得关注。
Console,WinForm,WPF,ASP.NET,Azure WebJob,WCF,Unity3d,UWP可以适当地了解。
注:此文是自学笔记所生,质量中下等,故要三思而后行。新手到此,不可照搬,应先研究其理象数,待能变通之时,自然跳出深坑。

C#基础 List ToArray List转换为数组_数组


举报

相关推荐

0 条评论