hi,i am trying to increase count by comparing two strings using Contains function. My code is,
int count = 0;
string strSize = "";
for (int i = 0; i < dts.Rows.Count; i++)
{
strSize += dts.Rows[i]["sizeid"].ToString() + ",";
}
if (strSize.Length > 0)
strSize = strSize.Substring(0, strSize.Length - 1);
// After executing strSize="3,4,5,10"
if (strMainSize.Length > 0)
strMainSize = strMainSize.Substring(0, strMainSize.Length - 1);
// After executing strMainSize ="1,2,3,4,5,10,45"
strM = strMainSize.Split(',');
for (int s = 0; s < strM.Length; s++)
{
if (strSize.Contains(strM[s]))
{
count++;
chkSize.Items.FindByValue(strM[s]).Selected = true;
}
}
var totalCount = count;
After executing this,totalCount should be equal to 4 but it is giving me 5,means first time when it is checking condition for strSize.Contains(strM[s]) it is getting true instead of false. Can anybody tell me why this is happening.
Other thing when i am doing same in other application it is working fine.
code i wrote is,
int count=0;
string[] str = { "3", "4", "5", "10"};
string[] strM = {"1","2","3","4","5","10","45","50" };
for (int s = 0; s < strM.Length; s++)
{
var stM = strM[s];
if (str.Contains(strM[s]))
{
count++;
chkSize.Items.FindByValue(strM[s]).Selected = true;
}
}
int totalCount = count;
here o/p:totalCount=4. Can anybody tell me the difference between two.