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 trialAtanu Mondal
1,976 PointsThread.Sleep() working without adding the namespace using System.Threading, why?
using System;
class Program {
static void Main(string[] args)
{
//Part2 using system Namespace
Console.WriteLine("Welcome to cat store");
Thread.Sleep(1000);
Console.WriteLine("Done Sleeping");
}
why the above code is working for me, i haven't used the namespace System.Threading; at the top.
BTW i am using visualStudio.
thanks for any explanation or any reference in advance.
2 Answers
Steven Parker
231,275 PointsThis is funny, most folks ask questions about why things are not working.
If you hover your mouse over the term, VS should pop up a helper message that shows you where the term is defined.
Zachary Greeley
903 PointsEven though you have already included the "System" namespace at the top of your code, you still need to specify the full namespace for the Thread class because it is not directly in the System namespace.
Instead, the Thread class is in the System.Threading namespace, which is like a sub-folder inside the System namespace. So to access the Sleep method of the Thread class, you need to use the full namespace of System.Threading before the Thread.Sleep method call.