Extension methods on a struct

前端 未结 4 437
野趣味
野趣味 2020-12-17 07:46

Can you add extension methods to a struct?

4条回答
  •  情话喂你
    2020-12-17 08:34

    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;
            }
        }
    }
    

提交回复
热议问题