Hi. In C++ ie we can do this:


code.cpp

#include vars.h


main()
{
if var1 == 1 { printf("ok"); }
return true; }

The point is not the code itself, but that #include.

I'd like to have a *.cs file containing some numeric variables.
But not a Class, just a normal text file containing variables like const int var1 = 1;

How can I do that?

Recommended Answers

All 2 Replies

i am not sure if this is what you are looking for, but i believe you are looking for settings files. Basically they are files to store settings that you will use across your application which can be modified and are saved after the application is closed.

Also, look here:

http://msdn.microsoft.com/en-us/library/e6w8fe1b%28v=VS.71%29.aspx

it explains how to add constants to your classes.

Regards

Read about static
You could do something like this:

class Vars
    {
        public static int var1 = 1;
        public static double var2 = 3.42;
        //etc.
    }

Then use your variables like this:

int i;       
double d = Vars.var2;
i = Vars.var1;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.