Advertisement
Guest User

Cyclic Immutable List

a guest
Feb 14th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1.     class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             TasksList tl = new TasksList(new int[] { 1, 2, 3, 4, 5 });
  6.             Console.WriteLine("The tasks list length " + tl.Tasks.Length);
  7.         }
  8.     }
  9.  
  10.     class Task
  11.     {
  12.         private readonly TasksList list;
  13.         private readonly int id;
  14.  
  15.         public Task(TasksList list, int id)
  16.         {
  17.             this.list = list;
  18.             this.id = id;
  19.         }
  20.     }
  21.  
  22.     class TasksList
  23.     {
  24.         private readonly Task[] tasks;
  25.  
  26.         public TasksList(int[] ids)
  27.         {
  28.             var mutableList = new List<Task>();
  29.             foreach (int id in ids)
  30.             {
  31.                 Task t = new Task(this, id);
  32.                 mutableList.Add(t);
  33.             }
  34.  
  35.             this.tasks = mutableList.ToArray();
  36.         }
  37.  
  38.         public Task[] Tasks { get { return tasks; } }
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement