I have a class which defines few global variables as below:
namespace Algo
{
public static class AlgorithmParameters
{
public int pop_size = 100;
}
}
In my another csharp file, which also contains the main(), and in the main() I am declaring an array of type structure and the array size as pop_size but I am getting some error on "chromo_typ Population[AlgorithmParameters.pop_size];". Please find the code below. Am I using a incorrect syntax for array declaration of variable length size??
namespace Algo
{
class Program
{
struct chromo_typ
{
string bits;
float fitness;
chromo_typ() {
bits = "";
fitness = 0.0f;
}
chromo_typ(string bts, float ftns)
{
bits = bts;
fitness = ftns;
}
};
static void Main(string[] args)
{
while (true)
{
chromo_typ Population[AlgorithmParameters.pop_size];
}
}
}
}
Error is:
Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
Please help.