JohnathanMayhem

ARR

Nov 11th, 2022
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApplication2
  4. {
  5. public class MyArray : IArray
  6. {
  7. public int Length { get; }
  8. public double[] arr = new double[10000];
  9. int nextIndex = 0;
  10.  
  11.  
  12. public object this[int i]
  13. {
  14. get => arr[i];
  15. set => arr[i] = (int)value;
  16. }
  17.  
  18. public MyArray(int a)
  19. {
  20. this.Length = a;
  21. this.nextIndex = a;
  22. this.arr = new double [a];
  23. }
  24.  
  25.  
  26. public void Add(int value)
  27. {
  28. if (nextIndex >= arr.Length)
  29. throw new IndexOutOfRangeException($"Out of bounds");
  30. arr[nextIndex] = value;
  31. ++nextIndex;
  32. }
  33. }
  34. }
Add Comment
Please, Sign In to add comment