Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the C++/CLI equivalent for the 'const ' keyword in C#?

Tags:

c++-cli

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!

like image 553
PapaAtHome Avatar asked Dec 19 '22 19:12

PapaAtHome


1 Answers

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

like image 61
Jon Avatar answered Feb 23 '23 15:02

Jon