Integ Programming Flashcards
kupal ka ba?
is a set of fixed number of values called elements that can be accessed using integer index
array
on an array are
of the same data type
Elements
is used to store multiple values of the same data type at a time
without declaring a different variable name for each value. Array elements can be of any data type
array
is an array in which all elements are arranged like a list
one-dimensional array
The following example of one-dimensional array that can store 10 integers and all the array elements are
initialized to zero
int[] numbers = new int[10];
The following example shows how to assign values to individual array elements by using an index number
numbers[0] = 45;
numbers[4] = 23;
The example below shows how to initialize an array upon declaration:
double[] grades = { 2.50, 2.75, 1.25, 5.0, 1.50 };
in C# is used to process the elements of an array starting with index 0 up to the ending index. T
foreach statement
The following example shows how to use a foreach statement to access the all the
elements of the array grades:
foreach (double grade in grades)
{
Console.Write(grade + “ / “);
}
Output:
2.5 / 2.75 / 1.25 / 5 / 1.5 /
the array elements are arranged in rows and columns. The elements in this array are arranged in a
tabular form and are therefore stored and accessed by using two (2) indices: one (1) index refers to the row, and the other
refers to the column location.
a two-dimensional array,
The following example defines a two-dimensional array consisting of two (2)
rows and four (4) columns:
int[,] table = new int[2, 4];
The example below shows how to assign values to individual array elements by specifying the row and column numbers:
table[0, 1] = 18;
table[1, 3] = 4;
The following example shows how to initialize a two-dimensional array upon declaration:
int[,] table = {
{ 2, 3 },
{ 12, 5},
{ 3, 8 },
{ 18, 3 }
};
The following shows how to access the element of a two-dimensional array:
Console.WriteLine(table[3, 0]); //this prints the 18
in C# is a collection that behaves as a dynamic array where the array size can dynamically increase as
required
ArrayList class
The ArrayList class is defined in the
System.Collections namespace
The following example shows how to create an ArrayList:
ArrayList nameList = new ArrayList();
is used to add an element to the list
Add() method
The following is the example of adding elements on the ArrayList
named nameList:
nameList.Add(“Jack Paul”);
nameList.Add(“Adrian Castro”);
nameList.Add(“Peter Cruz”);
nameList.Add(“Angela Cruz”);
The elements of an ArrayList can be accessed by specifying an integer index. For example:
Console.WriteLine(nameList[2]); //this will print Peter Cruz
is used to process all the elements of an ArrayList
The foreach loop
Example of foreach loop
foreach (string name in nameList)
{
Console.Write(name + “, “);
}
Output:
Jack Paul, Adrian Castro, Peter Cruz, Angela Cruz
is a sequential collection of characters that is used to represent text
string
In C#, a string is an object of class string in the
System namespace