Tuesday, 28 January 2014

Foreach loop in C#

A foreach loop works on each object in a collection, and provides that object as the appropriate type within the loop syntax:
 foreach (string in array) 

Example For an Foreach Loop :-
using System;
namespace foreach
  class Program
     static void Main(string[] args)
        string[] arr = new string[4]; // declaring array

        arr[0] = "Munesh";
        arr[1] = "jhon";
        arr[2] = "dom";
        arr[3] = "roy";

        //retrieving value using foreach loop
        foreach (string name in arr)
           Console.WriteLine("Hi " + name);

Hello Munesh
Hello Jhon
Hello Dom
Hello roy

No comments:

Post a Comment

Paging in html table using javascript

I demonstrated how to use HTML tables on the client for a very simple client-side paging solution. I have heard from several people who p...