Extension methods on a struct

Ghyath Serhal picture Ghyath Serhal · Jan 11, 2011 · Viewed 21.1k times · Source

Can you add extension methods to a struct?

Answer

Pranay Rana picture Pranay Rana · Jan 11, 2011

Yes, you can add extension methods on structs. As per the definition of extension method, you can easily achieve it. Below is example of extension method on int

namespace ExtensionMethods
{
    public static class IntExtensions
     {
        public static bool IsGreaterEqualThan(this int i, int value)
        {
            return i >= value;
        }
    }
}