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 9005161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:04:24+00:00 2026-06-16T01:04:24+00:00

I need a few control Arrays for my project but my code is generating

  • 0

I need a few control Arrays for my project but my code is generating errors.

Here is how I give a normal control properties (this code works fine)

TextBox stamText = new TextBox()  
{ 
    Location = new Point(15, 50), 
    Text = "55", 
    Width = 30, 
    Height = 30
};

Here is the code I tried to do the same but for an array of controls

TextBox[] stamText = new TextBox[8]  
{ 
    Location = new Point(15, 50), 
    Text = "55", 
    Width = 30, 
    Height = 30 
};

I get errors after each property in the {} saying “;” is expected.

Does anyone know how to solve this problem (giving control arrays properties)?

***EXTENDED

Okay so my program is a form which keeps track of players stats while we tabletop roleplay.

So say I am in a room with Bill, Jim, and I

I click the “Add player” button on the form and it adds a player along with a bunch of controls to do with that player

*AddPlayer Button clicked*
Addplayer()

Public void AddPlayer()
{
*Add a bunch of controls*
 checkbox(i)
 textbox(i)
}
i += 1

Now everyone got hit a 10. So i go to alter everyones stamina by -10

if for i = 0 to players added 
   if checkbox(i) = checked then textbox(i).text = (text - 10)

So i need them to be arrays so i can alter multiple peoples stats at once by going through a for loop.

  • 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-16T01:04:25+00:00Added an answer on June 16, 2026 at 1:04 am

    You seem to have a confusion about the object and collection intializers. The object intializer, which you are using in your first case, works likes this:

    Object initializers let you assign values to any accessible fields or properties of an object at creation time without having to explicitly invoke a constructor.

    class Cat
    {
        // Auto-implemented properties. 
        public int Age { get; set; }
        public string Name { get; set; }
    }
    
    Cat cat = new Cat { Age = 10, Name = "Fluffy" };
    

    The collection initializer, which you use in your second case, works like this:

    Collection initializers let you specify one or more element initializers when you initialize a collection class that implements IEnumerable. The element initializers can be a simple value, an expression or an object initializer. By using a collection initializer you do not have to specify multiple calls to the Add method of the class in your source code; the compiler adds the calls.

    List<int> digits = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    

    In your example that is throwing the error, you are creating an array of 8 textboxes with the collection intializer but you are passing in the object intializer instead. The reason you get the error about the ; is because the ; is used to separate the objects you are adding into the collection. The compiler expects to see 8 textboxes being added in the collection, each separated by a ;. Here is one way you could fix this:

    TextBox[] stamText = new TextBox[8]  
    { 
        new TextBox() { Location = new Point(15, 50), Text = "55", Width = 30, Height = 30 },
        new TextBox() { Location = new Point(15, 50), Text = "55", Width = 30, Height = 30 },
        new TextBox() { Location = new Point(15, 50), Text = "55", Width = 30, Height = 30 },
        new TextBox() { Location = new Point(15, 50), Text = "55", Width = 30, Height = 30 },
        new TextBox() { Location = new Point(15, 50), Text = "55", Width = 30, Height = 30 },
        new TextBox() { Location = new Point(15, 50), Text = "55", Width = 30, Height = 30 },
        new TextBox() { Location = new Point(15, 50), Text = "55", Width = 30, Height = 30 },
        new TextBox() { Location = new Point(15, 50), Text = "55", Width = 30, Height = 30 } 
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have few questions on this as selenium always need windowid to get control
I need this up and running quick but I spent the last few hours
I need to impl a few basic features in this server: display a nice
I'm having a windows form. In this form I've datagrid control which has few
For a few reasons - I need to design my own control for WPF.
I've been working a few days on this spinner control, though I haven't had
For reasons that are beyond my control I need to store huge arrays (10000+
I found a few threads on this using the search feature, but nothing for
I'm been wanting to create a user control, but before I do I need
Hello fellow programmers, got a few problem here. I am adding a user control

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.