Click here to Skip to main content
14,695,660 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
Hi, i am very new to and c#. Now i want to loop through the array in c#. can you give me a example. Thanks in advance
Updated 3-Jan-15 12:32pm

If you do not know how to write a simple loop that accesses each value in an Array, I believe you are at ground-zero in terms of programming in C#, let alone using ASP.NET.

There's nothing wrong with being at "ground-zero;" we all start there :) And, the good thing is: if you start now, within a week or two you will never think you are "new" to C# again.

I've posted several times here on what I think are good resources (some free) for developing a basic competency in C# .NET: [^].

I encourage you to focus your study on first mastering the essential elements of C# .NET programming; there are certain things you need to learn which are common to almost all programming languages.

I would be concerned that if you do not start with a "foundation" in C# then moving on to the complex world of ASP.NET is going to be very difficult.

Essentials (imho):

Creating "Higher-Level Objects:" in .NET C# those would be NameSpace, Class (static and non-static), Struct, Enum

"Scope" which means how to manage how the names of different objects you have created are evaluated at any given moment in the compilation/execution of your code

Flow-Of-Control: Loops: for, foreach, while, do. If/Else and Switch/Case structures.

Understanding .NET Types: Value Types, Reference Types; understanding Type conversion.

Variables (in .NET 'Fields) how to declare them, control their accessibility (scope).


Methods (static and non-static): passing parameters, returning results. passing by value, passing using 'out and 'ref.

Simple Math operators. operator precedence.

Boolean comparison. understanding use of 'null, string.IsEmpty, etc.

Basic Data Structures: Arrays, Generic Lists.
Hi is the answer for your question..

ReferLoop through array

int[] nums = {
        lbl_dispaly.Text = "Numbers <br />";
        foreach (int num in nums)
            lbl_dispaly.Text += num.ToString() + "<br />";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900