Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >C#中string[]数组和list<string>泛型的相互转换 【转】

C#中string[]数组和list<string>泛型的相互转换 【转】

作者头像
DougWang
发布于 2020-02-18 08:17:51
发布于 2020-02-18 08:17:51
1.5K0
举报
文章被收录于专栏:java跬步java跬步

C#中string[]数组和list<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();        

}     } }

结果显示:

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2012-11-17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
3. C# break,continue
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 {     class Program {         static void Main(string[] args) {             Console.WriteLine("Output do{.. br
py3study
2020/01/08
2370
C# 静态与动态数组
C#中的数组是由System.Array类衍生出来的引用对象,因此可以使用Array类中的各种方法对数组进行各种操作。
王瑞MVP
2022/12/28
1.7K0
c# list<T>操作实例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication6 { class Program { static void Main(string[] args) { List<string[]> str1
zls365
2020/08/19
8700
c# list<T>操作实例
C# 并发安全集合ConcurrentBag取代List
List集合是非线程安全的,所以我们这里了解下安全集合ConcurrentBag。 控制台测试程序: using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyConcurrent
跟着阿笨一起玩NET
2020/03/18
3.5K0
C#线程初步
张哥编程
2024/12/19
600
C#线程初步
C#解析Json
目前我用到解析json数据的就只用到这个类库,用这个类库可以很方便的对于C#和JSON直接进行序列化和反序列化解析
ryzenWzd
2022/05/07
2.5K0
C#解析Json
C# 笔记之基本语法
标准输入输出: using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Console.WriteLine("hello world"); string Str = Console.ReadLine(); Console.WriteLine(Str);
王瑞MVP
2022/12/28
2160
WCF系列教程之WCF客户端调用服务
1、创建WCF客户端应用程序需要执行下列步骤 (1)、获取服务终结点的服务协定、绑定以及地址信息 (2)、使用该信息创建WCF客户端 (3)、调用操作 (4)、关闭WCF客户端对象 二、操作实例 1、
郑小超.
2018/01/26
2.1K0
C# WinForm 界面控件
1.首先插入新的子窗体form1,并设置IsMdiContainer = True 属性。
王瑞MVP
2022/12/28
3.3K0
C# WinForm 界面控件
C# 语言程序设计笔记
C#是一种最新的、面向对象的编程语言。它使得程序员可以快速地编写各种基于Microsoft .NET平台的应用程序,Microsoft .NET提供了一系列的工具和服务来最大程度地开发利用计算与通讯领域。他是从C和C++派生而来的,其与C/C++语法非常相似,并依附于.NET虚拟机的强大类库支持,各方面对强于C/C++.
王瑞MVP
2022/12/28
3.9K0
C# 字符与字符串操作
格式化字符串: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string Str1 = "hello lyshark";
王瑞MVP
2022/12/28
4030
C#高级程序设计Type类
是.net一种非常重要的机制,通过反射可以在运行时获取类的成员、属性、事件和构造方法等等。有了反射,使我们对类的类型了如指掌。
张哥编程
2024/12/13
1140
c#一个list去掉其中重复元素
立羽
2023/08/24
2050
C# 实现对网站Get与Post请求
通过配合new WebClient()自己封装接口HttpGetPage(string url,string coding)用户传入网站地址以及编码方式,即可下载指定页面到变量中。
王瑞MVP
2022/12/28
7260
C# 中的函数与方法
Out 方法返回多个参数: 类似与C++中的多指针传递,就是说可以一次性传出多个参数。
王瑞MVP
2022/12/28
7430
基于C# 的 WinForm 开发 (一、C# 快速入门)
成员变量不用赋值,局部变量必须赋值才能用 int a,b,c = 10; //是错误的
Gorit
2021/12/09
2.2K0
c#练手code
做一个控制台程序,要求输入三个任意整数,将三个数按从大到小的顺序输出。 根据排列组合,知道有6中情况,一是可以采用排序,不过有些小题大做。二是可以交换,输出。 方法一 采用交换,让a最大,b第二大,就行了。 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1
热心的社会主义接班人
2018/05/16
6600
C# 实现ping功能
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { System.Net.NetworkInformation.Ping
用户7705674
2021/11/03
8120
WCF系列教程之客户端异步调用服务
本文参考自http://www.cnblogs.com/wangweimutou/p/4409227.html,纯属读书笔记,加深记忆 一、简介 在前面的随笔中,详细的介绍了WCF客户端服务的调用方法,但是那些操作全都是同步的,所以我们需要很长的时间等待服务器的反馈,如何一台服务器的速度很慢,所以客户端得到结果就需要很长的时间,试想一下,如果客户端是个web项目,那么客户体验可想而知,所以为了不影响后续代码执行和用户的体验,就需要使用异步的方式来调用服务。注意这里的异步是完全针对客户端而言的,与WCF服务契
郑小超.
2018/01/26
1.2K0
.NET Timer控件基础用法
System.Timers.Timer aTimer =new System.Timers.Timer();  
用户5760343
2022/05/24
6590
相关推荐
3. C# break,continue
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档