Advertisement
Guest User

Example

a guest
Mar 22nd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp20
  8. {
  9.     class Program
  10.     {
  11.         //delegate int Howdy(char symbol, string text);
  12.  
  13.         static void Main(string[] args)
  14.         {
  15.             Func<char, string, int> GetValue;
  16.             GetValue = HowManySymbols;
  17.             GetValue += IndexOfFirst;
  18.             string text = Console.ReadLine();
  19.             char symbol = char.Parse(Console.ReadLine());
  20.             //Howdy howdy = HowManySymbols;
  21.             //howdy += IndexOfFirst;
  22.             //howdy.Invoke(symbol, text);
  23.             GetValue.Invoke(symbol, text);
  24.         }
  25.  
  26.         static int HowManySymbols(char symbol, string text)
  27.         {
  28.             int count = 0;
  29.             foreach (var letter in text)
  30.             {
  31.                 if (letter == symbol)
  32.                     count++;
  33.             }
  34.             return count;
  35.         }
  36.  
  37.         static int IndexOfFirst(char symbol, string text)
  38.         {
  39.             for (int i = 0; i<text.Length; i++)
  40.             {
  41.                 if (text[i] == symbol)
  42.                     return i;
  43.             }
  44.             return -1;
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement