@property - take it behind the woodshed and shoot it?

mist none at none.none
Fri Jan 25 07:16:41 PST 2013


On Friday, 25 January 2013 at 15:13:21 UTC, Jacob Carlborg wrote:
> The secret is to add "this" in front of the argument type you 
> want to the method to extend:
>
> namespace ExtensionMethods
> {
>     public static class MyExtensions
>     {
>         public static int WordCount(this String str)
>         {
>             return str.Split(new char[] { ' ', '.', '?' },
>                              
> StringSplitOptions.RemoveEmptyEntries).Length;
>         }
>     }
> }
>
> using ExtensionMethods;
>
> string s = "Hello Extension Methods";
> int i = s.WordCount();
>
> http://msdn.microsoft.com/en-us/library/vstudio/bb383977.aspx

Good. Main questions remain though: is property syntax allowed on 
extension methods? Is WordCount(s) call allowed?


More information about the Digitalmars-d mailing list