473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

namespace not found

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
3 2229
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
8
by: Marcin Kalicinski | last post by:
Is the code below ill formed (because operator >> is defined in different namespace than class B)? It fails with VS 2005 Beta. I don't know if I should redesign my code or if I should find a...
7
by: Kevin Newman | last post by:
I've been toying with a namespace manager, and wanted to get some input. So what do you think? if (typeof com == 'undefined') var com = {}; if (!com.unFocus) com.unFocus = {}; ...
7
by: Kai-Uwe Bux | last post by:
Hi folks, I observed something that puzzles me. When I do namespace xxx { using std::swap; } it appears that xxx::swap and std::swap are not strictly equivalent. In particular, I think...
2
by: Steve Richter | last post by:
I have a simple project that builds ok in Visual Web Developer, but which fails when I navigate to it at //localhost. The error is "namespace 'ac' could not be found". the problem page is at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.