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
this
Yell(this string message)...
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.
Outputs
Note that you should mark the parameter with
this