The virtual
goes at the beginning, the override
goes at the end. Also, you can get rid of the ref new String
, the compiler can figure out that you want the string constant to be treated as a String^
.
public ref class Foo sealed
{
public:
virtual String^ ToString() override
{
return "This is from class Foo";
}
};