Skip to content

Instantly share code, notes, and snippets.

@kostapc
Created April 19, 2019 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kostapc/2c440c036be97a72b75ad015d8b12f60 to your computer and use it in GitHub Desktop.
Save kostapc/2c440c036be97a72b75ad015d8b12f60 to your computer and use it in GitHub Desktop.
C# extensions methods example
using System;
using System.Threading;
namespace FunctionalExperiments
{
class Program
{
static void Main(string[] args)
{
SomeEmptyClass someObject = new SomeEmptyClass();
someObject.NewEmptyMethod();
string some = "aaaa";
some.NewMethod();
Console.ReadKey();
}
}
public static class StringExtensions
{
public static void NewMethod(this String self)
{
Console.WriteLine("hello here, i am " + self);
}
}
public static class SomeEmptyClassExtensions
{
public static void NewEmptyMethod(this SomeEmptyClass self)
{
Console.WriteLine("hello here");
}
}
public class SomeEmptyClass
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment