How do we know the number of common values between two lines from two different tables? using csharp.
table1.row[1]={5,6,3,4,1}
table2.row[3]={6,4,16,18,7,'2'}
// table2.row[3][5] is char mean number of duplicate value must be to return true (i make it char because i dont want program use this value whenthey do comparison)//
in this two table the funcion need to return true because we have two duplicate number and its the same value given by user in table2.row[3][5]
CodePudding user response:
There are many ways to find duplicates.
Here's one that doe not use anything C# specific.
var a = new [] {5,2,3,4,1};
var b = new [] {2,4,16,18,'2'};
List<object> commonElements = new(); // You can also just count 'duplicates'
for(int i = 0; i < a.Length; i )
for(int j = 0; j < b.Length; j )
if(b[j] == a[i])
{
commonElements.Add(a[i]);
break;
}
Console.WriteLine(string.Join(",",commonElements));
This prints 2,4
.
Later you can
if(commonElements.Count == user_input)
{
...
}
BTW. Please note that '2'
and 2
would not be considered the same.