Re: Declaring a constant in managed C++ for access from C#



GnG wrote:
Hello all,

Someone posted a similar question a while ago but there was
no response. Does anyone know the answer?

I have a managed C++ DLL which is used by a C# project.
In that DLL, I have code like this:

namespace Foo {
public __value const int Bar = 123;
};

It appears in the object browser when I'm in the C++
project, but it's not visible from the C# project. Why
not? Is there another way I'm supposed to do this?

I could put it into an enumeration, or make it a static
property of a class, but I'd rather not do that, if at all
possible.

Make it static. C# (and the.NET framework) has no real concept of a const
int. In C# when you declare a const int, you're really declaring a static
const int which always occupies memory and has an address, while in C++
you're declaring a constant, which may not even have an address.

-cd


.