Override .ToString method c#

后端 未结 7 1939
北海茫月
北海茫月 2020-11-27 07:52

Okay, so I wrote this program out of the exercise of a C# programming book (I\'m trying to learn here) and it asks for \"Override the ToString() method to return all

相关标签:
7条回答
  • 2020-11-27 08:20

    Without overiding ToString, if you tried to "get" the string value of an Employee, e.g.

    var employee1= new Employee(); Console.WriteLine(employee1);

    What you'd get is:

    ConsoleApplication1.Program+Employee

    Which provides no information at all to help you (or a UI) display relevant information.

    I use return _name + _number + _date + _salary; Which defaults to string,

    or a more verbose

    return "Name:" + _name + " Number:" + _number + " etc...";

    0 讨论(0)
提交回复
热议问题