Sunday, 3 December 2017

C# Program to Implement Principles of Delegates


Code:

using System;
class Program
{
      delegate string UppercaseDelegate(string input);
      static string UppercaseFirst(string input)
      {
        char[] buffer = input.ToCharArray();
        buffer[0] = char.ToUpper(buffer[0]);
        return new string(buffer);
      }
      static string UppercaseLast(string input)
      {
        char[] buffer = input.ToCharArray();
        buffer[buffer.Length - 1] = char.ToUpper(buffer[buffer.Length - 1]);
        return new string(buffer);
      }
      static string UppercaseAll(string input)
      {
        return input.ToUpper();
      }
      static void WriteOutput(string input, UppercaseDelegate del)
      {
        Console.WriteLine("Input String: {0}", input);
        Console.WriteLine("Output String: {0}", del(input));
      }
      static void Main()
      {
        WriteOutput("tom ", new UppercaseDelegate(UppercaseFirst));
        WriteOutput("tom", new UppercaseDelegate(UppercaseLast));
        WriteOutput("tom", new UppercaseDelegate(UppercaseAll));
        Console.ReadLine();
      }   
}



Output:

Input String: tom
Output String: Tom
Input String: tom
Output String: toM
Input String: tom
Output String: TOM


More C# Programs:

















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...