'Image'是'System.Web.UI.WebControls.Image'和'System.Drawing.Image之间的模糊引用 [英] 'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image

查看:85
本文介绍了'Image'是'System.Web.UI.WebControls.Image'和'System.Drawing.Image之间的模糊引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用图像,也为我的应用程序添加颜色。

我正在使用命名空间如下:

Hi,

I am using image and also color i my application.
and i am using namespace as bellow:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Net.Mail;
using System.Drawing.Imaging;
using System.Drawing;





现在显示错误。如果我删除



Now it shows error. if i remove

using System.Drawing;



然后错误显示颜色阻止,如果我使用System.Drawing.Imaging删除


then error shows in color block and if i remove

using System.Drawing.Imaging;

这个命名空间然后错误显示在图像块中。

那么两个命名空间实际上都需要。

this namespace then error shows in image block.
So which namespace is actual reqired for both.

推荐答案

使用所需的命名空间。

例如如果有一个类A属于命名空间N1和N2这里你可以做 -
Use the required namespace.
For e.g. if there is a class A that belongs to namespace N1 and N2 here is what you could do -
N1.A myObjectForN1 =  new N1.A();
N2.A myObjectForN2 =  new N2.A();


除了解决方案1:



首先,确保在同一个文件中确实需要这两种类型。可能会发生一个只是旧代码的残余。使用Visual Studio,执行此操作总是很有用:在代码编辑器中显示弹出菜单并使用 O rganize Usings=> R 移动未使用的使用。不要过度使用使用。 :-)



但是你可能真的在一个代码文件中使用这两种类型。所以,命名空间......



现在,了解命名空间是你需要的基础知识之一。没有完全理解,你不能做任何编程。错误消息清楚地告诉您什么是错的。您只需阅读以下主题:。



除了解决方案1中显示的技术之外,您还可以使用别名使用指令(不要与使用声明混在一起!): https:// msdn。 microsoft.com/en-us/library/sf0df423.aspx [ ^ ]:

In addition to Solution 1:

First of all, make sure you really need both types in the same file. It may happen that one is just a remnant of old code. With Visual Studio, it's always useful to do this: show popup menu in the code editor and use "Organize Usings" => "Remove Unused Usings". Don't overuse "using". :-)

But it's possible that you really use both types in one code file. So, namespaces…

Now, understanding of namespaces is one of the basics things you need. You cannot do any programming without full understanding. The error message tells you clearly what's wrong. You just need to read on the topic: .

In addition to the technique showed in Solution 1, you can use alias using directive (not to be mixed up with using statement!): https://msdn.microsoft.com/en-us/library/sf0df423.aspx[^]:
using WebImage = System.Web.UI.WebControls.Image;
using DrawingImage = System.Drawing.Image;

//...

WebImage image = //...

//...

DrawingImage image = //...



您可以选择任何一种方式,或将它们组合起来,具体取决于您的可读性和个人品味。



-SA


这篇关于'Image'是'System.Web.UI.WebControls.Image'和'System.Drawing.Image之间的模糊引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆