[.net] Global Variables in C++/CLI

Started by
1 comment, last by kustom 18 years, 1 month ago
Hi to all, Im learning to code in C++/CLI for giving support to my native C++ applications to .NET framework and i have a problem: i cant declare a global variable in my .cpp /clr of type .NET like: MyClass^ instance = gcnew MyClass(); i can declare it like local object inside a function but not as global :( May exist a especial form of declarate globals? or maybe it doesnt exist globals? im confused..................... Kustom
Advertisement
There are no global variables or functions in C#. But you can use static methods/properties/fields inside a static class instead.

public static class MyGlobalClass{  public static int MyGlobalField1 = 0;  //or use a static property  private static int myGlobalField2 = 0;  public static int MyGlobalField2  {    get { return this.myGlobalField2; }    set { this.myGlobalField2 = value; }  }}// use them like:void SomeMethod(){  MyGlobalClass.MyGlobalField1 = 3;  MyGlobalClass.MyGlobalField2 = 5;}
----------------------#include "signature.h"
Thanks Zubspace,

I think your code will be easy to write in C++/CLI instead C#

regards

Kustom

This topic is closed to new replies.

Advertisement