将字符串分配给字符串数组 [英] Assign a string into a array of string

查看:100
本文介绍了将字符串分配给字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个字符串分配给一个字符串数组。但编译器确实让我这样做



这是以下代码



string [] sSuccessCode;



sSuccessCode = row.EMPLOYEECODE;



请给我一些建议

i wanted to assign a string into a array of string.But the compiler does let me doing it

Here's the following code

string[] sSuccessCode;

sSuccessCode = row.EMPLOYEECODE;

please give me some suggestion

推荐答案

您可以通过以下任何一种方式将字符串分配给数组:



You can assign a string to an array in any of the following ways:

string[] sSuccessCode = new string[4];  //specify size
sSuccessCode[0] =row.EMPLOYEECODE;


santhosh和Trushank答案很好..



这是你问题的另一种方式。



santhosh and Trushank answer is fine..

this is another way for your issue.

string[] sSuccessCode;
        List<string> lstsSuccessCode = new List<string>();
        lstsSuccessCode.Add(row.EMPLOYEECODE);
        sSuccessCode = lstsSuccessCode.ToArray();


初始化数组大小: -

initialize array size:-
string[] sSuccessCode = new string[4];  //specify size
sSuccessCode[0] =row.EMPLOYEECODE;


这篇关于将字符串分配给字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆