Clear Method (Static Method In Array Class)


Syntax for Clear Method is : -Clear(array,index,length)

Clear Method takes three parameter, first is array, second is index and third is length. It assigns the zero value from the specified index to the length of an array specified in the clear method.
---------------------------------------------------------------------------------------------------------
using System;
 class ClearMethod
{
                static void Main()
                {
                                int[] arr = {1,2,3}; 
                                 Console.WriteLine("-----------------------------------");                                       
                                foreach(int i in arr)
                                {
                                                Console.WriteLine("Element in array is " + i);
                                }
                                Console.WriteLine("-----------------------------------");
                                Array.Clear(arr,0,2);        //It assign the zero value from the specified index to the length.
                                 foreach(int i in arr)
                                {
                                                Console.WriteLine("Element in array is " + i);
                                }
                                Console.WriteLine("-----------------------------------");
                }
}
 --------------------------------------------------------------------------------------------------------






Clear Method (Static Method In Array Class) Clear Method (Static Method In Array Class) Reviewed by Baljeet Singh on 07:05 Rating: 5

No comments:

Powered by Blogger.