Also interesting to point out the syntactical differences in this post compared to the previous one. I didn’t even have to lower case the “S” in String, but I did never the less just because I prefer the color.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace twoArray
{
class Program
{
static void Main(string[] args)
{
//populate the arrays
string [] arrayA =
{“dog”,”cat”,”wolf”,”flamingo”,”spider”,”?”,”7″,”orange”};
string [] arrayB =
{“fox”,”wolf”,”bear”, “7”,”cheese”,”spider”,”paper”,”cat”};
//loop through the contents of arrayA
//and comparing each element to each element in arrayB
//switch variable used to indicate whether a match was found
bool foundSwitch = false;
//outer loop for all the elements in arrayA[i]
for(int i = 0; i < arrayA.Length; i++)
{
//inner loop for all the elements in arrayB[j]
for (int j = 0; j < arrayB.Length;j++)
{
//compare arrayA to arrayB and output results
if( arrayA[i]== arrayB[j])
{
foundSwitch = true;
Console.WriteLine( “arrayA element \”” + arrayA[i] + “\” was found in arrayB” );
}
}
if (foundSwitch == false)
{
Console.WriteLine( “arrayA element \”” + arrayA[i] + “\” was Not found in arrayB” );
}
//set foundSwitch bool back to false
foundSwitch = false;
}
}
}
}
Suppose 3. kind C, B, A, each having 50 elements A and B are in element arrays The values are stored. Write a program similar elements) and address (represented by A, B together in c#
int[] arr1={1,5,4,8};
int[] arr2={1,2,3,4};
output:
1,4
If the arrays are of different length then how would we compare?