C# 中 'const ' 关键字的 C++/CLI 等价物是什么?

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

我试图在我的 C++/CLI 代码中声明以下内容。

public ref class MyClass
{
public:
    const String ^MyLuckyNumber = "One";

它在编译阶段不幸地失败了。但在 C# 中,以下工作。

public class MyClass
{
    public const string NowMyLuckyNumber = "Two";

如何在 C++/CLI 中声明 'const String^'? 我尝试 google 但没有成功!

我认为您要查找的关键字是 literal

literal String ^MyLuckyNumber = "One";

literal 关键字在您声明的变量上暗含 static const。此外,关键字需要在声明期间进行初始化,这是您在 static const 声明中所期望的。

MSDN Reference