내가는 C++ 프로그래머 해요, 그리고 난 내가 그래서 여기에 소스 코드를 상속을 테스트 할 수있는 작은 프로그램을 작성한 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();
}
}
}
출력 : Humain는 \ 호출과 구조에 대한 구축합니다 Personne 클래스는 왜 불리지 않았습니까 !!! C++에서 부모 클래스 생성자가 먼저 호출됩니다 !! 도와주세요!
[이 질문을보십시오 (http://stackoverflow.com/questions/12051/calling-base-constructor-in-c-sharp). – Andy0708
'Personne' _was_의 생성자가 호출되었습니다. 예상했던 생성자가 아닙니다. – shambulator
참고 사항 : * 매우 * 드물게 C#에서 소멸자를 정의하려고합니다. http://stackoverflow.com/questions/4898733/when-should-i-create-a-destructor – Timbo