You can create loops by using the iteration statements. When execution leaves a scope(loop), all automatic objects that were created in that scope are destroyed.
The following keywords are used in iteration statements:
1). For
2). Foreach
3). While
4). Do While
1).For :-
For one of the iterate statement, It will iterate in between the values. if you know number of iterations will be there that time go for for loop.
Syntax:-
public void Main() { for (int i = 0; i< 10; i++) { Console.WriteLine("i value : "+ i); } }
initialization:-
Example
<pre class="brush: csharp">// Comment
public class Testing {
public Testing() {
}
public void Method() {
/* Another Comment
on multiple lines */
int x = 9;
}
}
</pre>
2).Foreach :-
Foreach used mainly collections,arrays etc, It can be used when we don't know how many iterations it will take that time we go for Foreach.
Syntax:-
foreach(var variable in colletionname)
{
}
if user wants to iterate each row in class DataTable.
DataTable dt=new DataTable();
//you do not know how many rows in a Table then Go for foreach.
foreach(DataRow row in dt.Rows)
{
string col1=row["Col1"].Tostring();
}
Syntax:-
foreach(var variable in colletionname)
{
}
if user wants to iterate each row in class DataTable.
DataTable dt=new DataTable();
//you do not know how many rows in a Table then Go for foreach.
foreach(DataRow row in dt.Rows)
{
string col1=row["Col1"].Tostring();
}
1 Comments:
Nice site....Please refer this site also Our vision success!Training are focused on perfect improvement of technical skills for Freshers and working professional. Our Training classes are sure to help the trainee with COMPLETE PRACTICAL TRAINING and Real time methodologies
Dot Net coaching Institute in Chennai | Dot Net Training in Chennai | Dot Net Training Center in Chennai
Software Testing Training Institute in Chennai | Manual Testing Training in Chennai | Testing Courses in Chennai
Java Training Institute in Chennai | Java Course and Certification | Core Java Certification in Chennai
PHP Certification Class | PHP Course in Chennai | PHP Training Institute in Chennai