Extend with to take multiple arguments
Simen Kjærås
simen.kjaras at gmail.com
Thu Jun 6 07:22:38 UTC 2019
On Thursday, 6 June 2019 at 06:53:00 UTC, Bastiaan Veelo wrote:
> On Wednesday, 5 June 2019 at 21:02:39 UTC, 12345swordy wrote:
>> In C# you can initialize a class like this:
>> var exp = new Class { };
>>
>> That is just my opinion though.
>>
>> Alex
>
> I don’t understand your point. How is that different from D?
>
> auto exp = new class {};
>
> https://run.dlang.io/is/mupnDT
>
> Bastiaan.
First, new Class has different capitalization, so it's not an
anonymous class like in your code. Second, I believe 12345swordy
omitted some parts of his intended code, so a more correct
example would be:
class Class {
int n;
string s;
}
var exp = new Class { n = 4, s = "foo" };
This, D doesn't do. The equivalent would be:
class Class {
int n;
string s;
}
auto exp = new Class();
with (exp) {
n = 4;
s = "foo";
}
--
Simen
More information about the Digitalmars-d
mailing list