Compare Array String using C#.net

Posted by Naraayanan under C# on 6/12/2012 | Points: 10 | Views : 6007 | Status : [Member] | Replies : 2
Hi,
How to compare two array string using C#.net?
Eg:
 string[] com1 = { "COM6", "COM7" };
string[] com2 = { "COM6", "COM7","COM8" };


Here com1 and com2 are Array string.
Result:
COM8.
How to achieve this?

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/



Responses

Posted by: Naraayanan on: 6/12/2012 [Member] Starter | Points: 25

Up
0
Down
Hi friends,
I solve my problem. This is a solution.
 foreach (string com in com2 )

{
if (!com1.Contains(com))
{
MessageBox.Show(com);
}
}



Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 6/12/2012 [Member] Starter | Points: 25

Up
0
Down
 string[] com1 = { "COM6", "COM7" };


string[] com2 = { "COM6", "COM7", "COM8" };

for (int i = 0; i < com1.Length; i++)
{
for (int j = 0; j < com2.Length; j++)
{
if (com1[i].ToString() == com2[j].ToString())
{
// Do yours code
}
}
}


Ajay
ajaypatelfromsanthal.blogspot.in

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response