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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:12:48+00:00 2026-05-22T23:12:48+00:00

This is mainly a theoretical question i.e I don’t have any need for a

  • 0

This is mainly a theoretical question i.e I don’t have any need for a practical solution but when using foreach in MS V C# 2010 with the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] ints = new int[7]{0,0,0,0,0,0,0};
           foreach (int i in ints)
           {
                i = 10;

           }
           Console.ReadKey();
        }
    }
}

I get the error which tells me that I cannot modify i because it is a foreach variable,now if I wanted to I could do this simple task a number of other ways but the thing is I haven’t seen anything in the documentation which would disallow what I’m trying to do and I think foreach should give you the ability to change the variable within the list.

Is there something I’m missing?

  • 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-22T23:12:49+00:00Added an answer on May 22, 2026 at 11:12 pm

    Use a for loop instead and modify the values using ints[i]

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

Sidebar

Related Questions

This is mainly in regards to my question here , but I don't understand
Well, I started this topic mainly to share the experience I had with git-tfs
This is a trivial question, I was just wondering if I can use something
I'm trying to recreate a modernized version of this tutorial here - but I'm
I am trying to install gcc 4.6 (mainly for having C++0x better supported) in
I just made a subdomain on my webside mainly becouse i want a spesific
I am working on prime factorization on large numbers (mainly, project 3 @ project
When you add a subView to UIScrollView, should this change the smoothness, or anything
At the moment I am working on creating a small library for common data
I am trying to write a function that will pull valid phone numbers from

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.