C# 重写 ToString 方法,
分享于 点击 49545 次 点评:152
C# 重写 ToString 方法,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication27
{
class Program
{
static void Main(string[] args)
{
int x = 42;
string strx = x.ToString();
Console.WriteLine(strx);
Person p = new Person();
p.Name = "cxc";
p.Age = 23;
Console.WriteLine(p.ToString());
}
}
class Person
{
public string Name { get; set; }
public int Age { get; set; }
public override string ToString()
{
return "Person: " + Name + " " + Age;
}
}
}
相关文章
- 暂无相关文章
用户点评