FixedSize method in ArrayList

In this article I will explain the FixedSize method of ArrayList.
  • 2073

Introduction

The FixedSize method of ArrayList returns an ArrayList wrapper with a fixed size.If I make an ArrayList as Fixed then we check that whether the arraylist having the fixedsize or not through the IsFixedSize Property of ArrayList,if the arraylist have fixedsize then it return true otherwise false,In the following example I use conditional statement.

Example

namespace ConsoleApplication6

{

    class Program

    {

        static void Main(string[] args)

        {

            // Creates a new ArrayList.

            ArrayList arraylist = new ArrayList();

            arraylist.Add("One");

            arraylist.Add("Two");

            arraylist.Add("Three");

            arraylist.Add("Four");

            arraylist.Add("Five");

            arraylist.Add("Six");

            arraylist.Add("Seven");

            arraylist.Add("Eight");

            arraylist.Add("Nine");

            // Create a fixed-size ArrayList.

            ArrayList FixedSize = ArrayList.FixedSize(arraylist);

            // Display whether the ArrayLists have a fixed size or not.

            Console.WriteLine("ArrayList {0}.", arraylist.IsFixedSize ? "has a fixed size" : "does not have a fixed size");

            Console.WriteLine("FixedSize {0}.", FixedSize.IsFixedSize ? "has a fixed size" : "does not have a fixed size");

            Console.WriteLine();

        }

    }

}

 

Output

fixedsize.jpg 

 

Ask Your Question  

Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.