Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
215,954 Points

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

1 Answer

Steven Parker
Steven Parker
215,954 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.