Professional Documents
Culture Documents
BSIT 211
What is Array in C#?
Arrays are using for store similar data types grouping as a single unit. We can access
Array elements by its numeric index. The array indexes start at zero. The default value of
numeric array elements are set to zero, and reference elements are set to null.
class Program
{
static void Main()
{
// String arrays with 3 elements.
string[] arr1 = new string[] { "one", "two", "three" };
string[] arr2 = { "one", "two", "three" };
var arr3 = new string[] { "one", "two", "three" };
using System;
class Program
{
static void Main()
{
// Three-element array.
int[] array = { -5, -6, -7 };
// Pass array to Method.
Console.WriteLine(Method(array));
}
/// <summary>
/// Recieve array parameter.
/// </summary>
static int Method(int[] array)
{
return array[0] * 2;
}
}
Output: 10
A one dimensional array is a section of memory that contains structs or built in types or
pointers to something. This is usually accessed through a pointer, but it can be allocated
directly on the stack.
WHAT IS MULTIDIMENSIONAL?