In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge points about the initialization method of the C# base class. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article, let's take a look at it.
Initialization of base class
The derived class inherits the member variables and member methods of the base class. Therefore, the parent object should be created before the subclass object is created. You can initialize the parent class in the member initialization list.
The following program demonstrates this:
Using System
Namespace RectangleApplication
{
Class Rectangle
{
/ / member variable
Protected double length
Protected double width
Public Rectangle (double l, double w)
{
Length = l
Width = w
}
Public double GetArea ()
{
Return length * width
}
Public void Display ()
{
Console.WriteLine ("length: {0}", length)
Console.WriteLine ("width: {0}", width)
Console.WriteLine ("area: {0}", GetArea ())
}
} / / end class Rectangle
Class Tabletop: Rectangle
{
Private double cost
Public Tabletop (double l, double w): base (l, w)
{}
Public double GetCost ()
{
Double cost
Cost = GetArea () * 70
Return cost
}
Public void Display ()
{
Base.Display ()
Console.WriteLine ("cost: {0}", GetCost ())
}
}
Class ExecuteRectangle
{
Static void Main (string [] args)
{
Tabletop t = new Tabletop (4.5,7.5)
T.Display ()
Console.ReadLine ()
}
}
}
When the above code is compiled and executed, it produces the following results:
Length: 4.5breadth: 7.5area: 33.75cost: more than 2362.5 is all the content of this article "initialization method of C# Base Class". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 236
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.