Write a C# Sharp program to remove all the values except integer values from a given array of mixed values
- برمجة سي شارب
- برمجة
- 2021-05-15
- MarwaMohammed
الأجوبة
using System;
using System.Linq;
namespace exercises
{
class Program
{
static void Main(string[] args)
{
object[] mixedArray = new object[6];
mixedArray[0] = 25;
mixedArray[1] = "Anna";
mixedArray[2] = false;
mixedArray[3] = System.DateTime.Now;
mixedArray[4] = -112;
mixedArray[5] = -34.67;
Console.WriteLine("Original array elements:");
for (int i = 0; i < mixedArray.Length; i++)
{
Console.Write(mixedArray[i]+" ");
}
int[] new_nums = test(mixedArray);
Console.WriteLine("\n\nAfter removing all the values except integer values from the said array of mixed values:");
for (int i = 0; i < new_nums.Length; i++)
{
Console.Write(new_nums[i]+" ");
}
}
public static int[] test(object[] nums)
{
return nums.OfType<int>().ToArray();
}
}
}
القوائم الدراسية التي ينتمي لها السؤال