// CompareArrays() هنا قمنا بتعريف الدالة
static void CompareArrays(int[] arr1, int[] arr2)
if (arr1.Length == arr2.Length)
Console.Write("They have the same length");
Console.WriteLine("They have different length");
for (int i = 0; i < arr1.Length; i++)
Console.WriteLine(" but their values are not equals");
Console.WriteLine(" and their values are equal");
// CompareArrays() هنا قمنا بإنشاء 4 مصفوفات أحادية و من مقارنتهم بواسطة الدالة
static void Main(string[] args)
int[] arr1 = { 1, 2, 3, 4, 5 };
int[] arr2 = { 1, 2, 3, 4, 5 };
int[] arr3 = { 1, 2, 3, 6, 8 };
int[] arr4 = { 1, 2, 3, 4 };
Console.Write("Compare arr1 & arr2 => ");
CompareArrays(arr1, arr2);
Console.Write("Compare arr2 & arr3 => ");
CompareArrays(arr2, arr3);
Console.Write("Compare arr3 & arr4 => ");
CompareArrays(arr3, arr4);
using System;
class Program
{
// CompareArrays() هنا قمنا بتعريف الدالة
static void CompareArrays(int[] arr1, int[] arr2)
{
if (arr1.Length == arr2.Length)
{
Console.Write("They have the same length");
}
else
{
Console.WriteLine("They have different length");
return;
}
for (int i = 0; i < arr1.Length; i++)
{
if (arr1[i] != arr2[i])
{
Console.WriteLine(" but their values are not equals");
return;
}
}
Console.WriteLine(" and their values are equal");
}
// CompareArrays() هنا قمنا بإنشاء 4 مصفوفات أحادية و من مقارنتهم بواسطة الدالة
static void Main(string[] args)
{
int[] arr1 = { 1, 2, 3, 4, 5 };
int[] arr2 = { 1, 2, 3, 4, 5 };
int[] arr3 = { 1, 2, 3, 6, 8 };
int[] arr4 = { 1, 2, 3, 4 };
Console.Write("Compare arr1 & arr2 => ");
CompareArrays(arr1, arr2);
Console.Write("Compare arr2 & arr3 => ");
CompareArrays(arr2, arr3);
Console.Write("Compare arr3 & arr4 => ");
CompareArrays(arr3, arr4);
Console.ReadKey();
}
}