Thread overview | |||||
---|---|---|---|---|---|
|
March 21, 2007 Extension Method? | ||||
---|---|---|---|---|
| ||||
Hi all: Recently, I have found a undocumented(?) feture that a individual function with one parameter of array can be used as a method: int getLength(int[] arr) { return arr.length; } int[] foo = [1, 2, 3]; int len = foo.getLength(); Where I can find the information for this? Thanks a lot!. regards. |
March 21, 2007 Re: Extension Method? | ||||
---|---|---|---|---|
| ||||
Posted in reply to oldrev | oldrev wrote: > Hi all: > > Recently, I have found a undocumented(?) feture that a individual function with one parameter of array can be used as a method: > > int getLength(int[] arr) { return arr.length; } > int[] foo = [1, 2, 3]; > int len = foo.getLength(); > > Where I can find the information for this? http://www.digitalmars.com/d/arrays.html (look for "Functions as Array Properties", about halfway down the page) Note that it also works for functions with more than one argument, as long as the first one is an array. |
March 21, 2007 Re: Extension Method? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frits van Bommel | Frits van Bommel Wrote:
> oldrev wrote:
> > Hi all:
> >
> > Recently, I have found a undocumented(?) feture that a individual function with one parameter of array can be used as a method:
> >
> > int getLength(int[] arr) { return arr.length; }
> > int[] foo = [1, 2, 3];
> > int len = foo.getLength();
> >
> > Where I can find the information for this?
>
> http://www.digitalmars.com/d/arrays.html (look for "Functions as Array
> Properties", about halfway down the page)
> Note that it also works for functions with more than one argument, as
> long as the first one is an array.
Oops, I think I missed it. Thank you.
|
Copyright © 1999-2021 by the D Language Foundation