[Mono-list] Use of the {} with arrays
Colin JN Breame
colin at breame.net
Wed Sep 6 14:48:02 EDT 2006
On Wednesday 06 September 2006 19:41, Matt Raffel wrote:
> Colin JN Breame wrote:
> > Hi,
> >
> > The following compiles and runs fine:
> >
> > public class test_t {
> > public static void Main() {
> > System.Console.WriteLine(string.Join(" ", test()));
> > }
> > public static string[] test() {
> > string[] tmp = {"hello", "world"};
> > return tmp;
> > //return {"hello", "world"};
> > }
> > }
>
> changing your return to return new string[] {"hello", "world"}; works.
>
> I doubt the compiler knows that {"hello", "world"} should be a string
> array.
>
> Matt
It would be nice - I find typing "string[]{}" such a drag when all the info is
available to the compiler.
The compiler could be capable of infering the type of the array declaration as
it is the same type as the function return value. <pure speculation>I expect
that the jump from infering the type from a variable to infering the type
from a function return value type is very small in compiler code terms.</pure
speculation>
More information about the Mono-list
mailing list