好的,所以我在编写C#编程书时编写了这个程序(我试图在这里学习)并且它要求" 覆盖ToString()方法以返回所有数据成员 ".
我做得对吗?或者我只是成功地编写了编译但什么都不做的代码.ToString的目的是什么?
我花了大约30分钟来查看其他帖子,并没有想出来,所以我决定这样做.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication297
{
class Program
{
static void Main(string[] args)
{
String name = "Stormtrooper";
Employee s = new Employee(name);
Console.WriteLine("The type of hire is a {0}", s.Name);
Console.WriteLine("The identification number is {0}", s.Number);
Console.WriteLine("The date of hire is {0} ABY", s.Date);
Console.WriteLine("The standard galactic salary is...{0:C}", s.Salary);
}
class Employee
{
private string _name;
private string _number;
private int _date;
private int _salary;
public …
Run Code Online (Sandbox Code Playgroud) c# ×1