Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Kyaw Tun Sein
Kyaw Tun Sein
2,291 Points

At 8:33, the tutor doesn't explain why run time error if Documents is not instantiated to a new List<Document>. So, why?

Thanks for the comment Steven. Here is the video link: https://teamtreehouse.com/library/text-analytics-api-part-1

Steven Parker
Steven Parker
229,005 Points

You gave the time index, but you forgot to include a link to the video itself.

1 Answer

Steven Parker
Steven Parker
229,005 Points

Without initialization, you'd be trying to access the .Add() method of null.

This would of course produce an error. Unless established in the constructor, the properties of a newly created object (such as sentimentRequest here) are all null.

So to be able to use the .Add() method, the Document must first be initialized to an empty list.