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# Intermediate C# Abstraction Static Classes

Kevin Huang
Kevin Huang
5,806 Points

Question about status of _random changed

At 4:50, when you say the status of _random changed when we want to get a random number, I am a bit confused, since it is a static field in a static class, why _random is not immutable?

1 Answer

Steven Parker
Steven Parker
231,275 Points

While it's common for static global objects to be immutable, just defining it as "static" does not make it immutable. And in this case it's necessary for it to change so each call will produce a different value.

What "static" does is to allocate space for it associated with the class itself, so an instance doesn't need to be created.