The requested page is not available for the requested platform. You are viewing the content for Default platform.

Destructor must declare a body

CodeRush Classic shows the Destructor must declare a body code issue if a destructor does not declare a body.

Fix

Declare a body for the destructor.

Purpose

Highlights the destructor declaration statements, which would cause the Must declare a body because it is not marked abstract, extern or partial compilation error.

Example

class MyClass
{
    public MyClass(string name, int value)
    {
        Name = name;
        Value = value;
    }
    public string Name { get; private set; }
    public int Value { get; set; }~MyClass();
}

Fix:

class MyClass
{
    public MyClass(string name, int value)
    {
        Name = name;
        Value = value;
    }
    public string Name { get; private set; }
    public int Value { get; set; }
    ~MyClass()
    {
        System.Diagnostics.Trace.WriteLine(string.Format("\"{0}\" destroyed", Name));
    }
}