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

Only class types can contain destructors

CodeRush Classic shows the Only class types can contain destructors code issue if a non-class type contains a destructor.

Fix

Remove the destructor or convert a non-class type to a class.

Purpose

Highlights the destructor declarations, which would cause the Only class types can contain destructors compilation error.

Example

public struct MyData
{
    public MyData(string name, object value)
    {
        Name = name;
        Value = value;
    }
    public string Name { get; set; }
    public object Value { get; set; }~MyData()
    {
        MyDataCollection.RemoveListItem(Name);
    }
}

Fixes:

public class MyData
{
    public MyData(string name, object value)
    {
        Name = name;
        Value = value;
    }
    public string Name { get; set; }
    public object Value { get; set; }
    ~MyData()
    {
        MyDataCollection.RemoveListItem(Name);
    }
}
public struct MyData
{
    public MyData(string name, object value)
    {
        Name = name;
        Value = value;
    }
    public string Name { get; set; }
    public object Value { get; set; }
}