zoukankan      html  css  js  c++  java
  • C#中List〈string〉和string[]数组之间的相互转换

    1,从System.String[]转到List<System.String>

    System.String[] str={"str","string","abc"};

    List<System.String> listS=new List<System.String>(str);

    2, 从List<System.String>转到System.String[]

    List<System.String> listS=new List<System.String>();

    listS.Add("str");

    listS.Add("hello");

    System.String[] str=listS.ToArray();

    测试如下:

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

    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                System.String[] sA = { "str","string1","sting2","abc"};
                List<System.String> sL = new List<System.String>();
                for (System.Int32 i = 0; i < sA.Length;i++ )
                {
                    Console.WriteLine("sA[{0}]={1}",i,sA[i]);
                }
                sL = new List<System.String>(sA);
                sL.Add("Hello!");
                foreach(System.String s in sL)
                {
                    Console.WriteLine(s);
                }
                System.String[] nextString = sL.ToArray();
                Console.WriteLine("The Length of nextString is {0}",nextString.Length);
                Console.Read();
            }
        }
    }

    结果显示:

     
    详细出处参考:http://www.jb51.net/article/32390.htm

  • 相关阅读:
    Struts的ONGL
    深度解析 Qt 中动态链接库
    QTcpSocket 发送数据的几种方法
    QT GUI总结
    Qt 插件学习(一)
    Qt自定义窗口部件
    Qt事件机制浅析
    VS2008 Qt Designer 中自定义信号槽
    Q窗口操作函数(窗口最大化,全屏,隐藏最大化最小化按钮)
    QT中窗口刷新事件的学习总结
  • 原文地址:https://www.cnblogs.com/swtool/p/3642741.html
Copyright © 2011-2022 走看看