Advertisement
BSO90

First Index Of

Jul 5th, 2021
1,259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2.  
  3. namespace FirstIndexOf
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string source = Console.ReadLine();
  10.             char target = char.Parse(Console.ReadLine());
  11.  
  12.             Console.WriteLine(FirstIndexOf(source, target));
  13.  
  14.         }
  15.  
  16.         public static int FirstIndexOf(string source, char target)
  17.         {
  18.  
  19.             int targetFirstIndex = -1;
  20.             // Remove the line below then add your implementation.
  21.  
  22.             for (int i = 0; i < source.Length; i++)
  23.             {
  24.                 if (source[i] == target)
  25.                 {
  26.  
  27.                     targetFirstIndex = i;
  28.                     break;
  29.                 }
  30.             }
  31.  
  32.             return targetFirstIndex;
  33.         }
  34.     }
  35. }
  36.  
  37.            
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement