Write a C# Sharp program to remove all duplicate elements from a given array and returns a new array
- برمجة سي شارب
- برمجة
- 2021-05-29
- ahmadghneem
الأجوبة
using System;
using System.Linq;
namespace exercises
{
class Program
{
static void Main(string[] args)
{
object[] mixedArray = new object[8];
mixedArray[0] = 25;
mixedArray[1] = "Anna";
mixedArray[2] = false;
mixedArray[3] = 25;
mixedArray[4] = System.DateTime.Now;
mixedArray[5] = 112.22;
mixedArray[6] = "Anna";
mixedArray[7] = false;
Console.WriteLine("Original array elements:");
for (int i = 0; i < mixedArray.Length; i++)
{
Console.WriteLine(mixedArray[i]);
}
object[] result = test(mixedArray);
Console.WriteLine("\nAfter removing duplicate elements from the said array:");
for (int i = 0; i < result.Length; i++)
{
Console.WriteLine(result[i]);
}
}
public static object[] test(object[] mixedArray)
{
return mixedArray.Distinct().ToArray();
}
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال