Advertisement
loleckek228

4.6

Sep 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _4._6
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] integers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  10.             int[] numbers = { 1, 1, 1, 1, 1, 1 };
  11.             writeArray(ref integers);
  12.             Console.WriteLine();
  13.             add(ref integers, 11);
  14.             writeArray(ref integers);
  15.             Console.WriteLine();
  16.             remove(ref integers, 9);
  17.             writeArray(ref integers);
  18.             Console.WriteLine();
  19.             transfer(ref integers, ref numbers);
  20.             writeArray(ref integers);
  21.         }
  22.  
  23.         static void add(ref int[] array, int element)
  24.         {
  25.             int[] newArray = new int[array.Length + 1];
  26.  
  27.             for (int i = 0; i < array.Length; i++)
  28.             {
  29.                 newArray[i] = array[i];
  30.             }
  31.             newArray[array.Length] = element;
  32.             array = newArray;
  33.         }
  34.  
  35.         static void remove(ref int[] array, int index)
  36.         {
  37.             int[] newArray = new int[array.Length - 1];
  38.             int count = 0;
  39.             for (int i = 0; i < array.Length; i++)
  40.             {
  41.                 if (index == i) continue;
  42.                 newArray[count] = array[i];
  43.                 count++;                
  44.             }
  45.             array = newArray;
  46.         }
  47.  
  48.         static void transfer(ref int[] array, ref int[] arrayForTransfer)
  49.         {
  50.             array = arrayForTransfer;
  51.         }
  52.  
  53.         static void writeArray(ref int[] array)
  54.         {
  55.             for (int i = 0; i < array.Length; i++)
  56.             {
  57.                 Console.Write(array[i] + " ");
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement