Advertisement
Guest User

Untitled

a guest
Jan 10th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             item[] items = new item[5];
  14.  
  15.             for(int i = 0;i < items.Length; i++)
  16.             {
  17.                 items[i] = new item();
  18.             }
  19.             OutputArray(items);
  20.             item n = items[0];
  21.             item x = items[1];
  22.  
  23.             Change(ref n,ref x);
  24.             OutputArray(items);
  25.             Console.ReadKey();
  26.         }
  27.         public static void Change(ref item Last,ref item New)
  28.         {
  29.             item temp = (item)Last.Clone();
  30.             Last = New;
  31.             New = temp;
  32.         }
  33.         public static void OutputArray(item[] a)
  34.         {
  35.             foreach(item n in a)
  36.             {
  37.                 Console.Write(n.id + " ");
  38.             }
  39.             Console.WriteLine();
  40.         }
  41.     }
  42.     class item : ICloneable
  43.     {
  44.         public static Random random = new Random();
  45.         public int id;
  46.         public item()
  47.         {
  48.             id = random.Next(0, 255);
  49.         }
  50.         public object Clone()
  51.         {
  52.             return this.MemberwiseClone();
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement