如何查找列表项的第一个元素的第一个字符 [英] How to find List item's first element first char

查看:94
本文介绍了如何查找列表项的第一个元素的第一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我很麻烦.我的问题是我必须匹配两个列表项(两个都有一个元素(列表的大小为1)第一个字符...

看起来很简单,但是已经战斗了2个小时..

谢谢大家...

Hi guys,
I am in deep trouble. My problem is I have to match two list items(both had one element''s(size of the list is 1) first character...

appears to be simple but fighting since 2 hrs..

thanks guys...

推荐答案

那里不需要ToCharArray ...

如果您这样声明列表:
There is no need of ToCharArray there...

If you declared your lists like this:
List<string> list1; 
List<string> list2;


那么这个测试就足够了:


Then this test will be enough:

if (list1[0][0] == list2[0][0])
{
    //first chars of first elements are equal
}


否则,请提供有关列表的更多详细信息.


Otherwise, please give more details about your lists.


if(list1[0].ToString().ToCharArray()[0] == list2[0].ToString().ToCharArray()[0]))
{
   //chars are equal 
}
else
{
   //are not
}



怎么样?



How about this???


您可以找到第一个字符ListItem1.SelectedItem.Text.ToCharArray()[0]将为您提供Selected项的第一个字符.
You can find the first char ListItem1.SelectedItem.Text.ToCharArray()[0] will give you the first charecter of the Selected item.


这篇关于如何查找列表项的第一个元素的第一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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