Register now or log in to join your professional community.
I don't have a good knowledge in C++ Syntax So..
In C# you can Create A new Class and use it for all Project level variables and you may want to put a connection string and File locations Special Folder Locations a certain Registry Key etc…
e.g...
1-Create a new class by pressing (Shift+alt+C) or Right click on Project Name From Solution Explorer >Add>Class
2.Give your class a name ,Click on add
3.in the class create static variables like :
public class BikeDetails
{
internal static string Model_Name;
internal static double Engine_Bore;
internal static bool Fuel_Injection;
}
4.you can reach your variables by calling the class like :
private void Save_BikeDetails_Click(object sender, EventArgs e)
{
BikeDetails.Model_Name="Honda CBR600rr -2006";
BikeDetails.Engine_Bore =598;
BikeDetails.Fuel_Injection = true;
}
In c++
1 - Global variable
you can declare the global variable on .cpp file and extern it on any another file
example
in file1.cpp
int var =0;
and
in file2.cpp
extern int var ;
so you can use var in file1.cpp and in file2.cpp
or
you can declare the var as static variable on class or struct
example on struct
in filestruct.h
struct x{
static int var;
};
in filestruct.cpp
int x::var =0;
and use var
x::var =5;.....
example on class
in fileclass.h
class x{
public:
static int var;
};
in fileclass.cpp
int x::var =0;
and use var
x::var =5;.....
Please follow the instruction while declaring a global variable