re: Write a function that shows off something unique or interesting about the language you're using VIEW POST

TOP OF THREAD FULL DISCUSSION
re: In Ruby we can monkeypatch to easily add functionality to any class. For example: class String def yell! self.upcase + "!!!" end end...
 

That's amazing that Ruby and other languages can extend built-in classes as well.

Anyways, to show off C#, here you go.

C# can extend any classes using extension method syntax.

using System;

namespace extensionmethod
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!".Yell());
        }
    }

    public static class StringExtensions
    {
        public static string Yell(this string message)
        {
            return $"{message.ToUpper()}!!!";
        }
    }
}

Outputs

c:\misc\Sources\throwaway\extensionmethod>
$ dotnet run
HELLO WORLD!!!!

Note that you should mark the parameter with this

Yell(this string message)...
code of conduct - report abuse