@Shervan360 , Welcome to Microsoft Q&A, based on my test, I reproduced your problem.
Here is some explanation.
First, I make sure that your console app is a .NET app based on the code Math m = new();
.
Second, as the Microsoft doc finalizers said, there's no output when we used it in the NET app.
.NET 5 (including .NET Core) or a later version: There's no output, because this implementation of .NET doesn't call finalizers when the application terminates.
Also, based on my test, it will not give output I'm Destructor...
even if I used your code in a .NET Framework 4.8. console app.
After checking, I find that we need to use Trace.WriteLine
instead of Console.WriteLine
to show the output.
Tested result in .net framework 4.8 when using Trace.WriteLine:
Hope my explanation could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.