Advertisement
VodVas

CleanCode_ExampleTask2.cs

Dec 18th, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.40 KB | Software | 0 0
  1. public static int FindElementIndex(this int[] array, int element)
  2. {
  3.     int defaultIndex = -1;
  4.  
  5.     if (array == null)
  6.     {
  7.         throw new ArgumentNullException("Массив не может быть null.", nameof(array));
  8.     }
  9.  
  10.     for (int i = 0; i < array.Length; i++)
  11.     {
  12.         if (array[i] == element)
  13.         {
  14.             return i;
  15.         }
  16.     }
  17.  
  18.     return defaultIndex;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement