On Thursday, 10 October 2019 at 16:33:47 UTC, H. S. Teoh wrote:
On Thu, Oct 10, 2019 at 03:58:02PM +, jmh530 via
Digitalmars-d-learn wrote:
On Thursday, 10 October 2019 at 15:47:58 UTC, Just Dave wrote:
> In C# you can do something like:
>
>
> if (obj is Person)
> {
> var
On Thu, Oct 10, 2019 at 03:58:02PM +, jmh530 via Digitalmars-d-learn wrote:
> On Thursday, 10 October 2019 at 15:47:58 UTC, Just Dave wrote:
> > In C# you can do something like:
> >
> >
> > if (obj is Person)
> > {
> > var person = obj as Person;
> > // do stuff with p
On Thursday, 10 October 2019 at 15:47:58 UTC, Just Dave wrote:
In C# you can do something like:
if (obj is Person)
{
var person = obj as Person;
// do stuff with person...
}
where you can check the type of an object prior to casting.
Does D have a similar mechanism
On Thursday, 10 October 2019 at 15:53:20 UTC, Adam D. Ruppe wrote:
On Thursday, 10 October 2019 at 15:47:58 UTC, Just Dave wrote:
if (obj is Person person)
Looks the same as D's
if(auto person = cast(Person) obj) {
// use person in here
} else {
// it was some other type
}
Excellent
On Thursday, October 10, 2019 9:47:58 AM MDT Just Dave via Digitalmars-d-
learn wrote:
> In C# you can do something like:
>
>
> if (obj is Person)
> {
> var person = obj as Person;
> // do stuff with person...
> }
>
> where you can check the type of an object prior
On 10/10/19 6:47 PM, Just Dave wrote:
In C# you can do something like:
if (obj is Person)
{
var person = obj as Person;
// do stuff with person...
}
where you can check the type of an object prior to casting. Does D have
a similar mechanism? It's so widely use
On Thursday, 10 October 2019 at 15:47:58 UTC, Just Dave wrote:
if (obj is Person person)
Looks the same as D's
if(auto person = cast(Person) obj) {
// use person in here
} else {
// it was some other type
}
Even though static solutions would be more performance minded,
I'd actually prefer to see the runtime equivalent so I don't have
to rethink how I think as performance isn't really my major
concern right now.
In C# you can do something like:
if (obj is Person)
{
var person = obj as Person;
// do stuff with person...
}
where you can check the type of an object prior to casting. Does
D have a similar mechanism? It's so widely useful in the C# realm
that they even added sy