tshad wrote:
I am setting a string collection as:
Specialized.StringCollection s1
But I get an error saying
namespace name 'Specialized' not found.
System.Collections.Specialized.StringCollection s1 does work.
But I do have:
using System.Collections;
Why doesn't the program recognize this and force me to put the whole
namespace in?
Because namespaces do not work that way. Or rather, using directives do not
work that way. Namespaces must always be referred to by their full name.
This arguably prevents some readability issues, because it saves you from
wondering whether "Specialized" is a namespace or a class in
System.Collections (with StringCollection as a nested class).
If you want a shorthand, then use either
using System.Collections.Specialized;
or
using StringCollection = System.Collections.Specialized.StringCollection;
The former imports the whole namespace and the latter just the class (this
is also the syntax to use for assigning aliases). In Visual Studio, you can
right-click any unresolved class name and choose "Resolve" to automatically
add the appropriate import.
--
J.