Tutorial
Arrays in General
Declaring an array doest not create an array, it has to be initialized. |
Initializing an array:
int[ ] data = new int[4]{1, 2, 3 4}; |
Table 2. The System.Array Class Methods. BinarySearch: :This method searches a one-dimensional sorted Array for a value, using a binary search algorithm. Clear : clears an array and sets an array to 0. Clone : copy of the Array. Copy : This method copies a section of one Array to another Array and performs type casting and boxing as required. CopyTo : This method copies all the elements of the current one-dimensional Array to the specified one-dimensional Array starting at the specified destination Array index. CreateInstance : This method initializes a new instance of the Array class. GetEnumerator : This method returns an IEnumerator for the Array. GetLength : This method returns the number of items in an Array. GetLowerBound : This method returns the lower bound of an Array. GetUpperBound : This method returns the upper bound of an Array. GetValue : This method returns the value of the specified item in an Array. IndexOf : This method returns the index of the first occurrence of a value in a one-dimensional Array or in a portion of the Array. Initialize : This method initializes every item of the value-type Array by calling the default constructor of the value type. LastIndexOf : This method returns the index of the last occurrence of a value in a one-dimensional Array or in a portion of the Array. Reverse : This method reverses the order of the items in a one-dimensional Array or in a portion of the Array. SetValue : This method sets the specified items in the current Array to the specified value. Sort : This method sorts the items in one-dimensional Array objects. |
Array Class Properties IsFixedSize Return a value indicating if an array has a fixed size or not. IsReadOnly Returns a value indicating if an array is read-only or not. IsSynchronized Returns a value indicating if access to an array is thread-safe or not. Length Returns the total number of items in all the dimensions of an array. Rank Returns the number of dimensions of an array. SyncRoot Returns an object that can be used to synchronize access to the array. |
Array Length:: using System;
|
Example 2using System; //csc test_array_3.cs namespace same { public class ucap { public static string Ucase(string str) { str = str.ToLower(); string strempty = ""; char[] chEmpty = new char[]{' '}; foreach (string search in str.Split(chEmpty)) { strempty += char.ToUpper(search[0]); strempty += (search.Substring(1, search.Length - 1) + ' '); } return strempty; } } class test { static void Main() { Console.Write("Write a sentence :"); string str = Console.ReadLine(); string con_str = ucap.Ucase(str); Console.WriteLine("Line Entered :" + str); Console.WriteLine("Line Changed :" + con_str); } } }
|
Example: new line as is
using System; |
sorting data
using System; //csc test_array_5.cs namespace arraysort { class sortarray { public static void sorting(string[] word) { Console.WriteLine("Sorted Array:"); Array.Sort(word); foreach (string str in word) { Console.WriteLine(str); } //return word; } } class test { static void Main(string[] str) { Console.Write("Now hit enter :"); // to hold the curosr for enter key press Console.ReadLine(); } } // } |
sorting data, my confusion is here, I did not call any function or anything in test_array_5.cs, still does the job |
Note the difference
using System; |
Now note in this revision, constructor was summoned with the object. using
System; |