Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApplication
- {
- class Program
- {
- /*
- * Сделайте 3 метода:
- * - Удаление элемента из массива.
- * - Добавление элемента в массив.
- * - Перенос одного массива в другой.
- */
- static void Main ( string [] args )
- {
- int [] nums = new int [4] { 1,2,3,4 };
- int [] nums2 = Transfer ( nums );
- foreach ( int i in nums2 )
- {
- Console.WriteLine ( i );
- }
- }
- static int [] Delete ( int [] arr )
- {
- int [] newArray;
- if ( arr.Length > 1 )
- {
- newArray = new int [arr.Length - 1];
- for ( int i = 0 ; i < newArray.Length ; i++ )
- {
- newArray [i] = arr [i];
- }
- return newArray;
- }
- else
- {
- newArray = new int [1];
- newArray [0] = 0;
- return newArray;
- }
- }
- static int [] Add ( int [] arr )
- {
- int [] newArray = new int [arr.Length + 1];
- for ( int i = 0 ; i < newArray.Length ; i++ )
- {
- if ( i < arr.Length )
- {
- newArray [i] = arr [i];
- }
- else
- {
- newArray [i] = 0;
- }
- }
- return newArray;
- }
- static int [] Transfer ( int [] arr )
- {
- int [] newArray = new int [arr.Length];
- for ( int i = 0 ; i < newArray.Length ; i++ )
- {
- newArray [i] = arr [i];
- }
- return newArray;
- }
- }
- }
Add Comment
Please, Sign In to add comment