Is there a particular way to initialize an IList<T>? This does not seem to work:
IList<ListItem> allFaqs = new IList<ListItem>();
// Error I get here: Cannot create an instance of the interface 'IList<ListItem>'
ReSharper suggests to initialize it like so:
IList<ListItem> allFaqs = null;
But won’t that cause a Null Reference Exception when I go to add items to this list?
Or should I just use List<ListItem>?
Thanks!
The error is because you’re trying to create an instance of the interface.
Change your code to:
or
and it should compile.
You’ll obviously have to change the rest of your code to suit too.
You can create any concrete type that implements
IListlike this, soand so on, will all work.