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();
}
}
}
List<string>和string[]数组之间的相互转换,需要的朋友可以参考下的更多相关文章
- C#中List〈string〉和string[]数组之间的相互转换
1,从System.String[]转到List<System.String> System.String[] str={"str","string" ...
- c# string 和 byte[]数组之间转换
在文件流读取和存储过程当中,经常涉及到byte[]数组形式存储数据,再此过程中也涉及到String类型字符串和byte[]的类型转换,下面我们举例说明一下. 现在有一个字符串: string str ...
- c++中几种常见的类型转换。int与string的转换,float与string的转换以及string和long类型之间的相互转换。to_string函数的实现和应用。
1.string转换为int a.采用标准库中atoi函数,对于float和龙类型也都有相应的标准库函数,比如浮点型atof(),long型atol(). 他的主要功能是将一个字符串转化为一个数字,在 ...
- list,set,map,数组之间的相互转换详细解析
1.list转setSet set = new HashSet(new ArrayList()); 2.set转listList list = new ArrayList(new HashSet()) ...
- c++中string类对象和字符数组之间的相互转换
string类在c++中是一个模板类,位于名字空间std中,注意这里不是string.h,string.h是C字符串头文件. 将string类型转换为字符数组char arr[10];string s ...
- String,Integer,int类型之间的相互转换
String, Integer, int 三种类型之间可以两两进行转换 1. 基本数据类型到包装数据类型的转换 int -> Integer (两种方法) Integer it1 = new I ...
- string,const char*,char*之间的相互转换
1. string转const char* string s = "abc"; const char* c_s = s.c_str(); 2. const char*转string ...
- Java中字符串和byte数组之间的相互转换
1.将字符转换成byte数组 String str = "罗长"; byte[] sb = str.getBytes(); 2.将byte数组转换成字符 byte[] b={(by ...
- 【python】列表与数组之间的相互转换
安装numpy pip3 install numpy 列表转数组 np.array() import numpy as np a = [1, 2, 3] b = np.array(a) 列表转数组 a ...
随机推荐
- NSSearchPathForDirectoriesInDomains用法
iPhone会为每一个应用程序生成一个私有目录,这个目录位于: /Users/sundfsun2009/Library/Application Support/iPhone Simulator/Use ...
- 洛谷 题解 CF299A 【Ksusha and Array】
本蒟蒻又双叒叕被爆踩辣! 这就是道大水题 首先,题目意思: 给你n个数,要你找这些数字中找到一个能够被这些所有数字整除的数,若有多个,可任意输出其中一个,其实答案只有一个,因为在大于等于自己的数中能被 ...
- MRC ARC 混编
今天一个人问我 什么是MRC 什么是ARC 要是一个工程里用到了MRC和ARC 怎么办 我当时就无语了 什么情况 这是.... 好了正经一点 我说一下iOS5.0以后就开始可以使用ARC( Aut ...
- 数据库Oracle和MySQL 的不同
实例区别: MySQL是轻量型数据库,开源免费.Oracle收费,这个不是重点,,重点是它贵. MySQL一个实例可以操作多个库,而Oracle一个实例只能对应一个库. MySQL安装只有300多兆, ...
- C#语言和SQL Server数据库技术_前四章错题
1.在C#中,如果让某个方法只能被它所在的程序集内的其他方法访问,可使用(C)修饰这个方法. (选择一项) A:private B:protected C:internal D:以上都不对 2.下 ...
- Codeforces Round #605 (Div. 3) E - Nearest Opposite Parity
题目链接:http://codeforces.com/contest/1272/problem/E 题意:给定n,给定n个数a[i],对每个数输出d[i]. 对于每个i,可以移动到i+a[i]和i-a ...
- k近邻聚类简介
简介 在所有机器学习算法中,k近邻(K-Nearest Neighbors,KNN)相对是比较简单的. 尽管它很简单,但事实证明它在某些任务中非常有效,甚至更好.它可以用于分类和回归问题! 然而,它更 ...
- Python流程控制之分支结构
目录 if/else结构 多重if结构 嵌套if结构 练习 if/else结构 if如果,else否则 # java if(){ }else{ } # python if 条件: 语句 else: 语 ...
- ruby 构建API接口流程代码
来源:https://ruby-china.org/topics/25822 1.创建新项目 rails new api_demo 2.生成控制器: # 我们不需要生成资源文件 $ bundle ex ...
- 用span写一个特殊样式的1
用span写一个如下样式的 1 span { display: inline-block; width: 17px; height: 17px; background: var(--themeColo ...