我是 C++ 程序员,我是 C# 新手,我写了一个小程序来测试继承,所以这里是源代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lesson3_Class_inherit_
{
public class Personne
{
public string Name;
public int Age;
public Personne() { }
public Personne(string _Name, int _Age)
{
Name = _Name;
Age = _Age;
Console.WriteLine("Constrcut Personne Called\n");
}
~Personne()
{
Console.WriteLine("Destruct Personne Called\n");
}
};
class Humain : Personne
{
public string Langue;
public Humain(string _Name, int _Age,string _Langue)
{
Console.WriteLine("Constrcut Humain Called\n");
Name = _Name;
Age = _Age;
Langue =_Langue;
}
};
class Program
{
static void Main(string[] args)
{
Humain H1 = new Humain("majdi", 28, "Deutsch");
Console.ReadLine();
}
}
}
输出: Construct Humain Called\ 并且 Personne 类的构造没有被调用为什么!!!在 C++ 中,首先调用父类构造函数!请帮忙 !