D
Daniel Billingsley
I think it's really nice to be able to do code like
someVariable = someMethod(new SomeClass("some text"));
However, as method signatures are number and types of parameters, you're
limited to having one constructor that accepts a single string, for example.
Call me crazy, but wouldn't it be useful to be able to have a syntax where
you could set properties in a statement like the one above, without being
limited to just what you could incorporate into a ctor signature?
public class SomeClass
{
private string _var1;
private string _var2;
private string _var3;
// public properties Var1, Var2, and Var3 here
public SomeClass()
{
}
}
and then be able to say
someVariable = someMethod(new SomeClass(!Var2 = "some text",
!Var3="something else"));
The "!" being of course some convention I just made up. The point being
that it still allows the rather concise line above compared to the
following:
SomeClass cls = new SomeClass();
cls.Var2 = "some text";
cls.Var3 = "something else";
someVariable = someMethod(cls);
But it gives total flexibility on what's set before it is used in
someMethod(). (Think of the way "using" looks cleaner than the try..finally
(and test for null) blocks.
someVariable = someMethod(new SomeClass("some text"));
However, as method signatures are number and types of parameters, you're
limited to having one constructor that accepts a single string, for example.
Call me crazy, but wouldn't it be useful to be able to have a syntax where
you could set properties in a statement like the one above, without being
limited to just what you could incorporate into a ctor signature?
public class SomeClass
{
private string _var1;
private string _var2;
private string _var3;
// public properties Var1, Var2, and Var3 here
public SomeClass()
{
}
}
and then be able to say
someVariable = someMethod(new SomeClass(!Var2 = "some text",
!Var3="something else"));
The "!" being of course some convention I just made up. The point being
that it still allows the rather concise line above compared to the
following:
SomeClass cls = new SomeClass();
cls.Var2 = "some text";
cls.Var3 = "something else";
someVariable = someMethod(cls);
But it gives total flexibility on what's set before it is used in
someMethod(). (Think of the way "using" looks cleaner than the try..finally
(and test for null) blocks.