In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use the destructor in C#". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's go deep into the train of thought of Xiaobian. Let's study and learn how to use the destructor in C#.
Destructor in C #
The destructor of a class is a special member function of the class, which is executed when the object of the class is out of scope.
The name of the destructor is prefixed with a wavy (~) in front of the name of the class, which returns no value and no parameters.
Destructors are used to release resources before ending the program (such as closing files, freeing memory, and so on). Destructors cannot be inherited or overloaded.
The following example illustrates the concept of a destructor:
Using System
Namespace LineApplication
{
Class Line
{
Length of private double length; / / Lin
Public Line () / / constructor
{
Console.WriteLine ("object created")
}
~ Line () / / destructor
{
Console.WriteLine (object deleted)
}
Public void setLength (double len)
{
Length = len
}
Public double getLength ()
{
Return length
}
Static void Main (string [] args)
{
Line line = new Line ()
/ / set the length of the line
Line.setLength (6.0)
Console.WriteLine ("Line length: {0}", line.getLength ())
}
}
}
When the above code is compiled and executed, it produces the following results:
Object has been created line length: 6 object has been deleted thank you for reading, the above is "how to use the destructor in C#" of the content, after the study of this article, I believe that you have a deeper understanding of how to use the destructor in C#, the specific use of the need for practice to verify. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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: 0
*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.