Thursday, 15 October 2015

Use of Rank , index of, last Index of Clone and Binary Search in Array in C#

In C# there are two types of Copy:

Deep Copy - Copying the Address
Shallow Copy - Copying the value
Clone() - Creates a copy of Shallow Copy

For Binary Search array must be sorted

using System;
    class Program
    {
        static void Main(string[] args)
        {
            int[] testArray = new int[] { 25, 10, 20, 5, 30, 1, 15, 28 };
            Console.WriteLine(testArray.Rank);
            Array.Sort(testArray);
            Console.WriteLine(Array.IndexOf(testArray, 100));
            Console.WriteLine(Array.LastIndexOf(testArray,20));
            int[] clonearray = (int[])testArray.Clone();
            //For Binary Search array must be sorted
            Console.WriteLine(Array.BinarySearch(testArray, 10));
        }
    }

No comments:

Post a Comment