如何将字符串转换为列表字符串或列表数组 [英] How to convert string to list string or list array

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

问题描述





我正在使用以下代码检查字符串是否等于构造函数的字符串对象或使用以下代码



Hi,

I am using following code for checking that the string is equal to the string object of constructor or not using the following code

for (int m = 0; m < CANMsgIdList.Count; m++)
     {
       if ((CANMsgIdList[m].MsgId) == fieldFromDB)
                                                
       string [] arr = (CANMsgIdList[m].TimeStamp).ToList;

      }





此CANMsgIdList是一个构造函数对象列表,其中包含464523个对象



我正在检查是否有任何对象等于字符串



如果任何对象等于字符串然后我需要将构造函数的TimeStamp对象复制到列表数组或列表字符串



我正在尝试这样的不工作



任何人都可以帮我解决这个问题





谢谢

John



this CANMsgIdList is a list of constructor objects and contains 464523 objects in it

I am checking if any of the objects are equal to equal to string or not

If any object is equal to string then I need to copy the TimeStamp object of constructor to list array or list string

I am trying like this which is not working

Can anyone help me in solving this


Thanks
John

推荐答案

如果您正在使用字符串数组,那么您需要在声明时定义数组的大小,这不能修改。而是使用arraylist。



If you are using array of string then you need to define the size of the array while declaration and this can't be modified. Instead use an arraylist.

ArrayList arrLst1 = new ArrayList();
for (int m = 0; m < CANMsgIdList.Count; m++)
     {
       if ((CANMsgIdList[m].MsgId) == fieldFromDB)
                                                
       arrList1.Add(CANMsgIdList[m].TimeStamp.Tostring());
 
      }





希望这应该有用。



Hope this should work.


不确定你的意思是,你的对象是字符串还是其他类型。与字符串类型比较时,您的对象可能需要将其转换为字符串。

not sure what your saying, is your object a string or another type. Your object may require that you cast it to a string when comparing to a string type.
//try converting/casting to a string type
if (CANMsgIdList[m].MsgId.toString() == fieldFromDB.toString())


这篇关于如何将字符串转换为列表字符串或列表数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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