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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:38:33+00:00 2026-05-20T08:38:33+00:00

Hi I am a student I am getting this error: forreach statement cannot operate

  • 0

Hi I am a student I am getting this error:

forreach statement cannot operate on
variables of type ‘object’ because
‘object’ does not contain a public
definition for ‘GetEnumerator’

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string result = " ";
            foreach (string activity in listBox1.SelectedItems)
            {
                result += activity + "   ";
            }
            this.textBox1.Text = result;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Add(textBox2.Text);
            textBox2.Clear();
        }
    }
}

Pl. help me

  • 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-20T08:38:33+00:00Added an answer on May 20, 2026 at 8:38 am

    Your code works fine for me. However, your code will break if you’ve added something other than a string to your ListBox‘s Items collection (although this will produce a different error than what you’re apparently seeing).

    Can you add the code you use to populate this ListBox?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting an error - 'Could not start transaction; too many transaction already
I am trying to run this query and getting error Unknown relation alias programs
I'm getting this error for my CASE 5/6/7/8. I'm sure it's something obvious as
I have a student developing on Windows XP, and he's getting a strange error
I am getting this error when running junit test Testcase: testGet_User(Authentication.UserManagerTest): Caused an ERROR
I am getting this error when I run the program. It compiles successfully but
I am using this code... Server.Transfer(/Student/StudentControlPanel.aspx?username= + username); And getting the following Exception: InvalidOperationException
I am getting error while diclaring collName as static variable in Student class. Could
I am a student with a mainly electronics background getting into programing. The more
I'm a Engineering student and I'm attending a Database and Information Systems class this

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.