By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,424 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,424 IT Pros & Developers. It's quick & easy.

namespace not found

P: n/a
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?

Thanks,

Tom
Jul 11 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
Jul 11 '08 #2

P: n/a
Great thanks,

Tom

"Jeroen Mostert" <jm******@xs4all.nlwrote in message
news:48***********************@news.xs4all.nl...
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.

Jul 14 '08 #3

P: n/a

"tshad" <ts***@dslextreme.comwrote in message
news:Op**************@TK2MSFTNGP04.phx.gbl...
Great thanks,
Also as an aside,

I assume I would need both namespaces:

using System.Collections.Specialized;
using System.Collections

or in my case - 3 of them:

using System.Collections.Specialized;
using System.Collections;
using System.Collections.Generic;

using System.Collections won't do it for all of them. Only classes within
System.Collections.

Thanks,

Tom
Tom

"Jeroen Mostert" <jm******@xs4all.nlwrote in message
news:48***********************@news.xs4all.nl...
>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.StringCollectio n 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.


Jul 14 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.