[英]C# Inheritance. Console is not opening
我有兩個名為 car 和 vehicle 的類。 我從車輛 class 繼承了汽車 class。我正在嘗試在 program.cs 中運行它。 但是控制台正在打開和關閉。 控制台.Read(); 我做到了,但它的行為仍然相同。 它也不會報錯。 我不明白原因。 我正在分享代碼。
程序.cs
namespace _4_Encapsulation_and_Properties
{
class Program
{
static void Main(string[] args)
{
Car myCar = new Car();
myCar.Honk();
Console.WriteLine("My car brand is: " + myCar.brand + "My car model is: " + myCar.model);
Console.Read();
}
}
}
汽車.cs
namespace _4_Encapsulation_and_Properties
{
class Car : Vehicle // Child class
{
public string model = "Corolla";
}
}
車輛.cs
namespace _4_Encapsulation_and_Properties
{
class Vehicle // base Class
{
public string brand = "Toyota";
public void Honk()
{
Console.WriteLine("Düüd , Düüd!");
Console.Read();
}
}
}
我在錯誤的項目中編寫了代碼。 我為 Inheritance 創建了一個不同的項目,但是我在為封裝創建的項目中創建了我的類。 它沒有工作,因為 Inheritance 項目被選為 Startup 項目,而這個項目是空的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.