Guest User

Untitled

a guest
Aug 10th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. private char[] NewArray { get; set; }
  2.  
  3. public int Count => NewArray.Length;
  4.  
  5. public char this[int index] { get => NewArray[index]; set => Add(NewArray,value); }
  6.  
  7. public char[] Insert(char[] arr, int index, char element)
  8. {
  9. if (index < 0)
  10. {
  11. throw new Exception("Negatif değer girilemez");
  12. }
  13.  
  14. NewArray = new char[arr.Length + 1];
  15. var oldArrayIndex = 0;
  16. if (index >= NewArray.Length)
  17. {
  18. throw new Exception("İndex Numarası Büyük veye EŞİT Olamaz");
  19. }
  20.  
  21. for (int i = 0; i < NewArray.Length; i++)
  22. {
  23.  
  24. if (index != i)
  25. {
  26. NewArray[i] = arr[oldArrayIndex++];
  27. }
  28. else
  29. {
  30. NewArray[i] = element;
  31. }
  32.  
  33. }
  34. return NewArray;
  35. }
  36.  
  37. public char[] RemoveAt(char[] arr, int index)
  38. {
  39. var _newArray = new char[arr.Length - 1];
  40. var oldArrayIndex = 0;
  41. if (index < 0)
  42. {
  43. throw new Exception("Negatif değer girilemez");
  44. }
  45. if (index >= arr.Length)
  46. {
  47. throw new Exception("İndex Numarası Büyük veye EŞİT Olamaz");
  48. }
  49. for (int i = 0; i <= arr.Length; i++)
  50. {
  51. if (_newArray.Length == oldArrayIndex)
  52. {
  53. return _newArray;
  54. }
  55.  
  56. if (index != i)
  57. {
  58. _newArray[oldArrayIndex++] = arr[i];
  59. }
  60. else
  61. {
  62. _newArray[oldArrayIndex++] = arr[++i];
  63. }
  64. }
  65. return NewArray;
  66. }
  67.  
  68. public int Add(char[] arr ,char value)
  69. {
  70. NewArray = arr;
  71. var _newArray = new char[arr.Length+1];
  72.  
  73. _newArray = arr;
  74.  
  75. _newArray[arr.Length+1] = value;
  76.  
  77. return arr.Length+1;
  78. }
  79.  
  80. public bool Contains(char[] arr ,char value)
  81. {
  82. NewArray = arr;
  83. bool inList = false;
  84. for (int i = 0; i < arr.Length; i++)
  85. {
  86. if (arr[i] == value)
  87. {
  88. inList = true;
  89. break;
  90. }
  91. }
  92. return inList;
  93. }
  94.  
  95. public char[] Clear(char[] arr)
  96. {
  97. return arr = new char[] {};
  98. }
  99.  
  100. public int IndexOf(char[] arr,char value)
  101. {
  102. for (int i = 0; i <= arr.Length; i++)
  103. {
  104. if (arr[i] == value)
  105. {
  106. return i;
  107. }
  108. }
  109. return -1;
  110. }
  111.  
  112.  
  113. public void Remove(char[] arr ,char value)
  114. {
  115. var _NewArray = new char[arr.Length - 1];
  116. var oldArrayIndex = 0;
  117.  
  118.  
  119. for (int i = 0; i <= arr.Length; i++)
  120. {
  121. if (_NewArray.Length == oldArrayIndex)
  122. {
  123. return;
  124. }
  125.  
  126. if (arr[i] != value)
  127. {
  128. _NewArray[oldArrayIndex++] = arr[i];
  129. }
  130. else
  131. {
  132. _NewArray[oldArrayIndex++] = arr[++i];
  133. }
  134. }
  135.  
  136. }
  137.  
  138. }
Add Comment
Please, Sign In to add comment