[.net] Global Variables in C++/CLI
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
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;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement