using ConsoleApp10;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp10
{
internal class Person
{
private string name;
public string Name { get; set; }
private int age;
public int Age { get; set; }
public Person()
{
Console.WriteLine("无参构造方法。");
}
public Person(int Age) : this()
{
this.Age = Age;
Console.WriteLine("构造方法被调用。");
}
public Person(string Name, int Age) : this(Age)
{
this.Name = Name;
//this.Age = Age;
}
public void Speak()
{
this.Say();
Console.WriteLine("大家好,我叫" + Name + "今年" + Age + "岁。");
}
public void Say()
{
Console.WriteLine("大家好!");
}
}
}
Program(这里在C#中出现了错误,不知道该如何解决)
// See https://aka.ms/new-console-template for more information
using ConsoleApp10;(这里也出现了错误)
internal class Program
{
private static void Main(string[] args)
{
Person person1 = new Person(20);
person1.Name = "名字";
Person person2 = new Person("王俊凯", 19);
person1.Speak();
}
}