Visual C++ .NET/Class/initonly

Материал из .Net Framework эксперт
Версия от 12:05, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

initonly static field

 
#include "stdafx.h"
using namespace System;
ref class MyClass
{
   public:
   static initonly String^ name = "a";  // OK
};


initonly string

 
#include "stdafx.h"
using namespace System;
ref class MyClass
{
   initonly String^ name;
   public:
   MyClass(String^ first, String^ last)
   {
       name = first + last;
   }
   void Print()
   {
       Console::WriteLine(name);  // OK
   }
};
int main()
{
   MyClass^ r = gcnew MyClass("a", "a");
   r->Print();
}