About references and/or the use of the using keyword...

C

clintonG

When using Visual Studio.NET I observe adding a new Web Form may have
default References added such as...

References
o- System
o- System.Data
o- System.Drawing
o- System.Web
o- System.XML

The source code will often contain what seems to be redundant declarations
as follows...

using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.XML;

Is there any reason References and what is declared in the code-behind
should be synchronized? Is there in fact redundantcy in this context?

Finally, when converting a VB project that has a Reference to
Microsoft.VisualBasic is it sufficient to declare the use of the equivalent
namespace by using Microsoft.CSharp; declared in the code-behind? I could
not find any 'reference' to Microsoft.CSharp when trying to 'Add Reference.'

<%= Clinton Gallagher
 
D

Daniel O'Connell [C# MVP]

clintonG said:
When using Visual Studio.NET I observe adding a new Web Form may have
default References added such as...

References
o- System
o- System.Data
o- System.Drawing
o- System.Web
o- System.XML

The source code will often contain what seems to be redundant declarations
as follows...

using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.XML;

Is there any reason References and what is declared in the code-behind
should be synchronized? Is there in fact redundantcy in this context?

The using directive has nothign to do with references, it simply provides a
list of namespaces the compiler should consider when trying to resolve an
identifier to a type name.

using System;

means the compiler should consider Int32 as both Int32 and System.Int32. It
picks the one that exists and fails if more than one exists.

References are a totally different beast, they define assemblies you want to
import. What you are seeing here is that many assemblies have the same name
as the namespaces they contain.
Finally, when converting a VB project that has a Reference to
Microsoft.VisualBasic is it sufficient to declare the use of the
equivalent
namespace by using Microsoft.CSharp; declared in the code-behind? I could
not find any 'reference' to Microsoft.CSharp when trying to 'Add
Reference.'

Microsoft.VisualBasic.dll is an assembly which contains a large number of VB
support classes. VB's intrinsic functions are implemented in that dll.
System.dll also implements a couple classes in the namespace
Microsoft.VisualBasic, pretty much the same as it does for Microsoft.CSharp.

There is no Microsoft.CSharp assembly. The only Microsoft.CSharp namespace I
know of is contained in System.dll.
 
C

clintonG

Thanks for your comments Daniel.
I'm working on the conversion of a VB.NET app that includes a rerence to
Microsoft.VisualBasic.
This ASP.NET application functions as a dynamic process controller, i.e. a
wizard.

MSDN documentation describes both Microsoft.CSharp and Microsoft.VisualBasic
as namespaces that.

"...contain classes that support compilation and code generation..."

So it seemed the presence of the reference for the Microsoft.VisualBasic
namespace in the VB.NET application had relevance but removing that
reference, recompiling and running in debug mode results in a stable
application regardless. Hmmm?


<%= Clinton Gallagher
 
D

Daniel O'Connell [C# MVP]

clintonG said:
Thanks for your comments Daniel.
I'm working on the conversion of a VB.NET app that includes a rerence to
Microsoft.VisualBasic.
This ASP.NET application functions as a dynamic process controller, i.e. a
wizard.

MSDN documentation describes both Microsoft.CSharp and
Microsoft.VisualBasic
as namespaces that.

"...contain classes that support compilation and code generation..."

So it seemed the presence of the reference for the Microsoft.VisualBasic
namespace in the VB.NET application had relevance but removing that
reference, recompiling and running in debug mode results in a stable
application regardless. Hmmm?

It might have had uses, if the VB code used VB intrinsics (InStr or Left for
example). The converter may have fixed that.
 
C

clintonG

I pored over the VB source and used Tangible's Instant C# [1] for snippet
conversions -- it is quite good I might add -- I am not that conversant with
mapping the superfluous VB keywords and grammar but I'm sure getting there
the hard way.

As it turns out, I just learned how useful the call stack can be as it
helped me determine I had not initialized the PreRender event and this
conversion is now complete. The application is a process controller, i.e. a
wizard, and now I need to focus on extending its use of interfaces. Whoopee
:)

<%= Clinton Gallagher

[1] http://tangiblesoftwaresolutions.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top