Professional Documents
Culture Documents
Example:
int [ ] age={18,17,18,19,17};
OUTPUT
public void PrintArray( )
{ 1st number:1
Response.Write("3rd number:");
Response.Write (numbers[2]+"<br/>");
System generates an “Index out of range exception”
Insert(Int32, Object)) Inserts an element into the ArrayList at the specified index.
Example
List<int> marks = new List<int>();
In the collection “marks” you can only add
marks.Add(60);
integers and no other type.
marks.Add(80);
List<string> names = new List<string>(); In the collection “name” you can only add string .
name.Add("Susan");
In the collection “student” you can only add
List<Student> students = new List<Student>(); Student object .
Insert(Int32, T)) Inserts an element into the List<T> at the specified index.
Use while or do/while loops when you don’t know how many iterations are
needed
Posttest Loop
do
{
//Statements in loop
} while (Condition);
Example:
intTotal = 0;
while (intTotal != 0)
{
//Statements in loop
}
Example:
intTotal = 0;
do
{
//Statements in loop
} while (intTotal != 0);
Statements in body of loop will not execute if the final value is reached before
entry into the loop
Some code can get into an endless loop that is impossible to exit on its own
◦ Click on form’s close box
◦ Use Visual Studio IDE menu or toolbar to stop program
◦ Use the C# break statement
(whereas the foreach loop can only read data from the array)
The foreach loop will execute if the array has at least one element
column
Create object: a new instance of the object is created with new keyword
followed by the class name
Object Name
32
https://www.youtube.com/watch?v=G238zPCJBu4
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
namespace Lec3
{
public class Score
{
public string Admino { get; set; }
public int StudScore { get; set; }
}
}
}
}
ENTERPRISE APPLICATIONS DEVELOPMENT PROJECT COPYRIGHT © 2017 SIT 36
Step 3 – Declare the method in class
s1.StudScore = Convert.ToInt32(TextBoxScore.Text);
// call the AddScore method of new object s1
s1.AddScore();