• Saves Valuable Time
  • Trusted Accuracy for 12 Years
  • 15-Day Money-Back Guarantee

C# Equivalent to C++ Constructors & Destructors

The closest match in C# to a C++ destructor is an implementation of System.IDisposable. Note that the '~' operator in C# denotes a 'finalizer', not a destructor.

C++ C#
class Foo
{
public:
    Foo() : Foo(0)   //call to other constructor
    {
    }
    Foo(int i)
    {
    }

    ~Foo()   //destructor
    {
    }
};
class Foo: System.IDisposable
{
    public Foo() : this(0)   //call to other constructor
    {
    }
    public Foo(int i)
    {
    }

    public void Dispose()
    {
    }
}


Use C++ to C# Converter to convert from C++ to C#.     

Additional resource: C++ and C# Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.