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

  • Home
  • SEARCH
  • 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 6243975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:14:27+00:00 2026-05-24T12:14:27+00:00

I am attempting following code to create multiple instances of a class at run-time

  • 0

I am attempting following code to create multiple instances of a class at run-time and want to initialize also, but it is giving error:

A local variable named ‘inum’ cannot be declared in this scope because
it would give a different meaning to ‘inum’, which is already used in
a ‘parent or current’ scope to denote something else.

public class MyClass
{
    static int i=0;

    class A
    {
        public A()
        { 

        }
    }

    public static void Run()
    {
        string inum = "i";
        for (int j=1;j<=5;j++)
        {
            inum = inum + j.ToString();
            //Initialize Instance
            A inum = new A();
        }
    }
}
  • 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-05-24T12:14:27+00:00Added an answer on May 24, 2026 at 12:14 pm

    You appear to be trying to use variable names “dynamically”. That doesn’t work in C#, and you should change how you think about variables. If you want to create several instances, declare an array:

    public class MyClass
    {
        static A[] instances;
    
        class A
        {
            public A()
            { 
    
            }
        }
    
        public static void Run()
        {
            instances = new A[5];
            for (int j=0;j<5;j++)
            {
                instances[j] = new A();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code throws an error on the CreateIfNotExist method call. I am attempting
I am attempting to create the following code through the use of CodeDom: public
I'm attempting to create a new user using the following code snippet. using (var
I'm attempting to use the following code to serialize an anonymous type to JSON:
I get the following error when attempting to install RubyGems . I've tried Googling
I am attempting to run the following command in KornShell (ksh): set -A INDEXES
I get the following error when attempting to connect to a web service via
I am getting the following error when attempting to build my project in Visual
I'm attempting to run the following command in PHP (on Ubuntu): <?php if (exec(/home/johnboy/ffmpeg/ffmpeg
I get the following error when attempting to use django-openid-auth OpenID discovery error: No

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.