S
S
Sergey2021-11-04 16:54:28
C++ / C#
Sergey, 2021-11-04 16:54:28

How does Console.WriteLine() take a StringBuilder object?

I know that you can print a number, a string, even a function (more precisely, its return value).
But is it possible to print an object?
Does an object return a value?
How is this possible?

StringBuilder x=new StringBuilder("текст");
Console.WriteLine(x);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
edward_freedom, 2021-11-04
@Shull

Read the book about redefining ToString

public class Test
        {
            private string _text;
            public Test(string text)
            {
                this._text = text;
            }

            public override string ToString()
            {
                return _text;
            }
        }

var x = new Test("текст");
            Debug.WriteLine(x);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question