© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
5 replies
Sonath

Why does the following prints "Point" to the console instead of "(2, 3)"?

Point thing = new Point(2, 3);
System.Console.WriteLine(thing); // prints Point
System.Console.WriteLine(thing.ToString()); // prints (2, 3)

public class Point
{
    public int X {get; private set; }
    public int Y {get; private set; }

    public Point(): this(0, 0)
    {

    }

    public Point(int x, int y)
    {
        this.X = x;
        this.Y = y;
    }

    // using NEW not OVERRIDE
    public new string ToString()
    {
        return $"({X}, {Y})";
    }
}
Point thing = new Point(2, 3);
System.Console.WriteLine(thing); // prints Point
System.Console.WriteLine(thing.ToString()); // prints (2, 3)

public class Point
{
    public int X {get; private set; }
    public int Y {get; private set; }

    public Point(): this(0, 0)
    {

    }

    public Point(int x, int y)
    {
        this.X = x;
        this.Y = y;
    }

    // using NEW not OVERRIDE
    public new string ToString()
    {
        return $"({X}, {Y})";
    }
}

Is it because Console.WriteLine uses an object reference internally?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Why does Task 1 prints first instead of Task 3 - Async & Await
C#CC# / help
2y ago
❔ entry point in dll instead of application
C#CC# / help
3y ago
❔ Why and when does todoId property get updated i.e. its different between prints to console.
C#CC# / help
4y ago
❔ ✅ Prints System.Func`1[System.Int32] instead of actual int.
C#CC# / help
3y ago