Fixed Size to List

Viewed 27596

For declaration perspective the following is allowed

    IList<string> list= new string[3];
    list.Add("Apple");
    list.Add("Manago");
    list.Add("Grapes");

1) It compiles fine,But runtime i am getting "Collection was of fixed size" error. Ofcourse ,collection is dynamically grown by size,why did such declaration is accepted by complier ?

2) What are the different lists that i can assign to IList ? Example

IList<string> fruits=new List<string>();

Here I am assigning List to IList ,What are the various collection classes can i assign to IList?

3 Answers
Related