I am getting " Using directive is unneccesary" error on these two. What is the correct way to use them ?
Asked
Active
Viewed 362 times
-1
-
1The error is pretty clear to me: _"A `using namespace` directive can only be applied to namespaces; `Environment` is a type not a namespace"_. What do you expect that line to do? – CodeCaster Aug 14 '15 at 10:11
2 Answers
1
You can remove them, as Thread and Environment are not namespaces, but types, as also stated in the warning you get
using System.Threading
using System; // which already exists as the first using statement
Using statement is for including namespaces, which contain types, like classes, enums, and so on. By adding System.Threading
for example, you gain access to Thread
class.
Read Microsoft's explanation for more information;

tdgtyugdyugdrugdr
- 786
- 4
- 13
- 31
1
You can use usings like you have, sort of, you can name them such as
using Thread = System.Threading.Thread;
or
using Excel = Microsoft.Office.Interop.Excel;
For info https://msdn.microsoft.com/en-us/library/sf0df423.aspx

BugFinder
- 17,474
- 4
- 36
- 51