Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- internal class Program
- {
- private delegate string UppercaseDelegate(string input);
- private static void Main()
- {
- // Wrap the methods inside delegate instances and pass to the method.
- WriteOutput("ivandro", new UppercaseDelegate(UppercaseFirst));
- WriteOutput("ismael", new UppercaseDelegate(UppercaseLast));
- WriteOutput("ivandrofly", new UppercaseDelegate(UppercaseAll));
- WriteOutput("playstation", new UppercaseDelegate(UppercaseFirstLast));
- }
- private static string UppercaseAll(string input)
- {
- return input.ToUpper();
- }
- private static string UppercaseFirst(string input)
- {
- char[] buffer = input.ToCharArray();
- buffer[0] = char.ToUpper(buffer[0]);
- return new string(buffer);
- }
- private static string UppercaseFirstLast(string input)
- {
- char[] buffer = input.ToCharArray();
- buffer[buffer.Length - 1] = char.ToUpper(buffer[buffer.Length - 1]);
- buffer[0] = char.ToUpper(buffer[0]);
- return new string(buffer);
- }
- private static string UppercaseLast(string input)
- {
- char[] buffer = input.ToCharArray();
- buffer[buffer.Length - 1] = char.ToUpper(buffer[buffer.Length - 1]);
- return new string(buffer);
- }
- private static void WriteOutput(string input, UppercaseDelegate del)
- {
- Console.WriteLine("Your string before: {0}", input);
- Console.WriteLine("Your string after: {0}", del(input));
- }
- }
- // http://www.dotnetperls.com/delegate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement