Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp3
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Title = "4.6 Арсенал";
- string[] arr = { "qqq", "www", "eee", "rrr" };
- ShowArray(ref arr);
- // Удаление элемента массива
- DelElement(ref arr, 1);
- ShowArray(ref arr);
- // Добавление элемента массива
- AddElement(ref arr, "zzz");
- ShowArray(ref arr);
- // Перенос одного массива в другой
- string[] newArr = new string[0];
- CopyArray(ref arr, ref newArr);
- ShowArray(ref newArr);
- Console.ReadKey();
- }
- static void DelElement(ref string[] arr, int elemNumber)
- {
- for (int i = elemNumber; i < arr.Length - 1; i++)
- {
- arr[i] = arr[i + 1];
- }
- NewSize(ref arr, arr.Length - 1);
- }
- static void AddElement(ref string[] arr, string s)
- {
- NewSize(ref arr, arr.Length + 1);
- for (int i = 0; i < arr.Length; i++)
- {
- arr[arr.Length - 1] = s;
- }
- }
- static void NewSize(ref string[] arr, int size)
- {
- string[] arrTmp = new string[size];
- for (int i = 0; i < Math.Min(arr.Length, size); i++)
- {
- arrTmp[i] = arr[i];
- }
- arr = arrTmp;
- }
- static void CopyArray(ref string[] arrFrom, ref string[] arrTo)
- {
- NewSize(ref arrTo, arrFrom.Length);
- for (int i = 0; i < arrFrom.Length; i++)
- arrTo[i] = arrFrom[i];
- }
- static void ShowArray(ref string[] arr)
- {
- for (int i = 0; i < arr.Length; i++)
- Console.WriteLine(arr[i]);
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement