[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • Last Modified:

Foreach with Array

Hello

Can you write for me an example of using the foreach statement in conjuction with an array?

Thanks
0
Kokas79
Asked:
Kokas79
  • 3
  • 2
1 Solution
 
vinhnlCommented:
string[] names = {"microsoft","ibm"};
foreach (string item in names)
{
      Console.WriteLine(item);
}

Good luck
VINHNL
0
 
Kokas79Author Commented:
thank you.

is foreach just for viewing or do u use it to modify the contents as well?
0
 
vinhnlCommented:
Foreach is just for viewing.

item is read-only
0
 
vinhnlCommented:
But you can attribute of item if it is object:

System.Windows.Forms.Button[] names = {button1};
foreach (System.Windows.Forms.Button item in names)
{
      item.Text = "Hello";
}

Good luck
0
 
Kokas79Author Commented:
thanks a lot....very useful
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now