Write a C# Sharp program to create a new array containing the middle elements from the two given arrays of integers, each length 5

  • برمجة سي شارب
  • برمجة

Write a C# Sharp program to create a new array containing the middle elements from the two given arrays of integers, each length 5

Sample Output:

New array: -30 30

الأجوبة

using System;
namespace exercises
{
   class Program
    {       
        static void Main(string[] args)
        {         
           int[] item = test(new[] { 10, 20, -30, -40, 30 }, new[] { 10, 20, 30, 40, 30 }); 
           
           Console.Write("New array: ");
         
           foreach(var i in item)
            {
               Console.Write(i.ToString()+" ");
            }
        }        
       public static int[]  test(int[] nums1, int [] nums2)
          {
              return new int[] { nums1[2], nums2[2] };
          } 
   }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...