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 ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- item[] items = new item[5];
- for(int i = 0;i < items.Length; i++)
- {
- items[i] = new item();
- }
- OutputArray(items);
- item n = items[0];
- item x = items[1];
- Change(ref n,ref x);
- OutputArray(items);
- Console.ReadKey();
- }
- public static void Change(ref item Last,ref item New)
- {
- item temp = (item)Last.Clone();
- Last = New;
- New = temp;
- }
- public static void OutputArray(item[] a)
- {
- foreach(item n in a)
- {
- Console.Write(n.id + " ");
- }
- Console.WriteLine();
- }
- }
- class item : ICloneable
- {
- public static Random random = new Random();
- public int id;
- public item()
- {
- id = random.Next(0, 255);
- }
- public object Clone()
- {
- return this.MemberwiseClone();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement