0

I'm inside a for and I want to access to a Class.Constants. This Constants vars are in order like Constants.X1, Constants.X2....

I would like to access this constants inside my form like

for (i = 1; i = 10; i++)
{
  int a  = Constants.X + i;
  int b = Constants.X + "20";
}

Is this able to do?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Josep
  • 1
  • 9

1 Answers1

0

Yes it is possible.

Make a class that contains your constants.

namespace MyNameSpace{
     public class Constants{
          public const int x1 = 1;
          public const int x2 = 2;
     }
}

You will be able to use the class directly to get the constants if both the class are inside same namespace. Otherwise just use the namespace to use the Constants class.

public class myTestClass{
     for(var i = 0; i < 10; i++){
          int a = MyNameSpace.Constants.x1 + i;
          int b = MyNameSpace.Constants.x2 + i;
     }
}
Shahbaaz
  • 403
  • 5
  • 11