Conflicting namespaces??

  • Thread starter Thread starter Will
  • Start date Start date
W

Will

I've included both the System.Drawing namespance and the
System.Web.UI.WebControls namespace on my page. Both of
these have an Image class, so when I call the Image class
(refering to the System.Drawing namespace) can I do it
without having to write the entire string?
System.Drawing.Image... I get errors saying Image is
ambiguous otherwise.
 
Hi

Every namespace and type has a fully qualified name,
which uniquely identifies the namespace or type amongst
all others.

So use fully qualified name.

Ravikanth[MVP]
 
I've included both the System.Drawing namespance and the
System.Web.UI.WebControls namespace on my page. Both of
these have an Image class, so when I call the Image class
(refering to the System.Drawing namespace) can I do it
without having to write the entire string?
System.Drawing.Image... I get errors saying Image is
ambiguous otherwise.

Will,

Both VB.Net and C# support namespace aliases. You can use this
mechanism to give different (usually shorter) names to a specified
namespace.

VB.Net:

Imports Draw = System.Drawing
Imports WebUI = System.Web.UI.WebControls

' Create a System.Drawing Image:
Dim MyDrawImage As Draw.Image = Draw.Image.FromFile('myfile.bmp')

' Create a System.Web.UI.WebControls Image:
Dim MyWebImage As New WebUI.Image()

C#:

using Draw = System.Drawing;
using WebUI = System.Web.UI.WebControls;

// Create a System.Drawing Image:
Draw.Image MyDrawImage = Draw.Image.FromFile("myfile.bmp");

// Create a System.Web.UI.WebControls Image:
WebUI.Image MyWebImage = new WebUI.Image();


Hope this helps.

Chris.
 
Back
Top