Home > Net >  The size of the collection is a fixed abnormal what reason be
The size of the collection is a fixed abnormal what reason be

Time:05-18


As IList (o). The Add (o);
As IList (o). Insert (0, o);
The two statements will quote this exception, may be what reason be cause?

CodePudding user response:

We first have to determine what type of O, such as he had been readolnly collection, such as the list is immutable

CodePudding user response:

Assignment size is fixed, if instantiated directly add, there would be no this problem, the insert
After the assignment can be transformed into list To operate,

CodePudding user response:

Such as this

Try
{
Int [] LST=new int [] {1, 2, 3};
Var b=(LST as IList.) the Add (0);
}
The catch (Exception e)
{
//iint [] of course implement ilist, nt [] is, of course, immutable, so he can as ilst but don't add
}

CodePudding user response:

refer to the second floor love tea assistant to reply:
size is fixed, after the assignment if instantiated directly add, there would be no this problem, the insert
After the assignment can be transformed into list To operate,

Why the IList, cannot directly into the assignment?

CodePudding user response:

The
reference 3 floor wanghui0380 response:
like this

Try
{
Int [] LST=new int [] {1, 2, 3};
Var b=(LST as IList.) the Add (0);
}
The catch (Exception e)
{
//iint [] of course implement ilist, nt [] is, of course, immutable, so he can as ilst but don't add
}

thank you

CodePudding user response:

IList is an abstract interface that you regard him as a instance, of course
  •  Tags:  
  • C#
  • Related