Advertisement
bazmikel

DeleteSpecifiedItemFromArray

Mar 10th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. public void UsunSamochod(string numerRejestracyjny)
  2.         {
  3.             int index = 0;
  4.             if (iloscSamochodow > 0)
  5.             {
  6.                
  7.                 Boolean found = false;
  8.                 string[] tempArray = new string[iloscSamochodow];
  9.                 for (int i = 0; i < iloscSamochodow; i++)
  10.                     tempArray[i] = numeryRejestracyjne[i];
  11.  
  12.                 for (int i = 0; i < iloscSamochodow; i++)
  13.                 {
  14.                     if (numerRejestracyjny == tempArray[i])
  15.                     {
  16.                         tempArray[i] = null;
  17.                         found = true;
  18.                         index = i;
  19.                     }
  20.  
  21.                 }
  22.  
  23.  
  24.  
  25.                 if (found)
  26.                 {
  27.                     int j = 0;
  28.                     iloscSamochodow--;
  29.                     numeryRejestracyjne = new string[iloscSamochodow];
  30.                     for (int i = 0; i < iloscSamochodow + 1; i++)
  31.                     {
  32.                         if(i == index)
  33.                         {
  34.                             continue;
  35.                         }
  36.                         numeryRejestracyjne[j] = tempArray[i];
  37.                         j++;
  38.  
  39.  
  40.                     }
  41.  
  42.                    
  43.                 }
  44.                
  45.  
  46.  
  47.                 if (!found)
  48.                     Console.WriteLine("Nie udalo sie odnalesc podanego numeru rejestracji.");
  49.             }
  50.             else
  51.                 Console.WriteLine("Pusta lista numerow rejestracyjnych!");
  52.            
  53.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement