Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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...
Posted
Updated 17-May-11 1:08am
v2
Comments
Fabio V Silva 17-May-11 7:16am    
What have you tried so far?

There is no need of ToCharArray there...

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

Then this test will be enough:
C#
if (list1[0][0] == list2[0][0])
{
    //first chars of first elements are equal
}

Otherwise, please give more details about your lists.
 
Share this answer
 
if(list1[0].ToString().ToCharArray()[0] == list2[0].ToString().ToCharArray()[0]))
{
   //chars are equal 
}
else
{
   //are not
}


How about this???
 
Share this answer
 
Comments
Olivier Levrey 17-May-11 8:14am    
This works but you don't need ToCharArray. The String class has an indexed property and should be enough in this case.
I voted 4.
senguptaamlan 17-May-11 8:16am    
yeah very true.....just by impulse written the thing :)
fjdiewornncalwe 17-May-11 8:21am    
I agree with Olivier. +4.
You can find the first char ListItem1.SelectedItem.Text.ToCharArray()[0] will give you the first charecter of the Selected item.
 
Share this answer
 
Comments
Jayadheer Reddy 17-May-11 7:35am    
Wow it sounds great but it is not Presentation layer list. I am talking about List<t>(Collections)
Jayadheer Reddy 17-May-11 7:35am    
Wow it sounds great but it is not Presentation layer list. I am talking about List(Collections)
Try that way

List<string> lst1 = new List<string> { "string1" };
List<string> lst2 = new List<string> { "string2" };
           
if (lst1.First()[0] == lst2.First()[0])
{

}
</string></string></string></string>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900