I tried to declare the following in my C++/CLI code.
public ref class MyClass
{
public:
const String ^MyLuckyNumber = "One";
It fails misirably during the compile phase. But in C# the following works.
public class MyClass
{
public const string NowMyLuckyNumber = "Two";
How can I declare a 'const String^' in C++/CLI? I tried to google on it but no luck!
I believe the keyword you're looking for is literal
literal String ^MyLuckyNumber = "One";
the literal
keyword implies a static const
on the variable you're declaring. Also, the keyword requires an initialization during the declaration, something you'd expect from a static const
declaration.
MSDN Reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With