Docs: The "New object initialization syntax" example code does not work in Focus Mode

Created on 27 Dec 2019  Â·  6Comments  Â·  Source: dotnet/docs

This code does not run (I have not tried it locally in VS or VSCode--could be a 'using' declaration issue, but that shouldn't be an issue in Focus Mode) :

public class Path : IEnumerable<Point3D>
{
private List<Point3D> points = new List<Point3D>();
public IEnumerator<Point3D> GetEnumerator() => points.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => points.GetEnumerator();

public void Add(Point3D pt) =&gt; points.Add(pt);

}

public static class Extensions
{
public static void Add(this Path path, double x, double y, double z) => path.Add(new Point3D(x, y, z));
}


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Area - C# Guide .NET Interactive P1 Pri2 doc-bug dotnet-csharprod

Most helpful comment

Thanks for writing this @bunda3d

The problem is due to an issue in the underlying try.net experience used on docs. An update will get deployed this month, and that will enable us to fix this.

I've added this to the list of planned work for this sprint.

/cc @LadyNaggaga @aprilspeight

All 6 comments

The new object initialization syntax works fine for me.

image

That is not the code I posted.

@bunda3d, My fault.
I think the example you're referring to misses the following using statements:

using System.Collections;
using System.Collections.Generic;

and misses a Point3D declaration which could be like this:

public class Point3D
{
    private double _x;
    private double _y;
    private double _z;

    public Point3D(double x, double y, double z)
    {
        _x = x;
        _y = y;
        _z = z;
    }
}

You may need to wait for @BillWagner to review this. I also think that it will be better to add an entry point (Main method) to the example for further illustration.

I was thinking it needed "using" statements, but that doesn't usually need to be considered in the "focus mode" editor, for whatever reasons.

Thanks for writing this @bunda3d

The problem is due to an issue in the underlying try.net experience used on docs. An update will get deployed this month, and that will enable us to fix this.

I've added this to the list of planned work for this sprint.

/cc @LadyNaggaga @aprilspeight

Closing as duplicate of #20753

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Eilon picture Eilon  Â·  3Comments

sime3000 picture sime3000  Â·  3Comments

JagathPrasad picture JagathPrasad  Â·  3Comments

gmatv picture gmatv  Â·  3Comments

mekomlusa picture mekomlusa  Â·  3Comments