Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7820133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:10:43+00:00 2026-06-02T07:10:43+00:00

I have a class which defines few global variables as below: namespace Algo {

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:10:50+00:00Added an answer on June 2, 2026 at 7:10 am

    You don’t specify the size when you declare the variable, you specify it when you create the instance of the array:

    chromo_typ[] Population = new chromo_typ[AlgorithmParameters.pop_size];
    

    Or if you separate the declaration and creation:

    chromo_typ[] Population;
    Population = new chromo_typ[AlgorithmParameters.pop_size];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which defines a historical extraction on a database: class ExtractionConfiguration
I have a class called EventConsumer which defines an event EventConsumed and a method
I have a Exception base class which defines a stream function: class Exception {
I have an application App1 which defines class A and uses instances of this
Suppose I have a file X.h which defines a class X, whose methods are
I have some logic, which defines and uses some user-defined types, like these: class
I have done a few projects lately using a Database Object super class which
I have 3 classes: an interface class that defines a few methods 2 classes
Say I have a simple class AClass with a public member f1 which can
My situation I have an entity model with a base class ItemBase which defines

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.