public static class MyExtensions
{
public static bool TextBoxIsEmpty(TextBox txtControl, ErrorProvider eP)
{
if (txtControl.Text == string.Empty)
{
eP.SetError(txtControl, "You must Enter something!");
return true;
}
else
{
eP.Clear();
return false;
}
}
}
我在整个项目中都使用此函数来验证空文本框。它正常工作,直到我将一个用户控件添加到我的 WinForm 之一。特别是,当网格的数据源更改时,该用户控件的实例将添加到我的表单中,但我收到此错误。
Error 129 The call is ambiguous between the following methods or properties: 'DominateVehicle.Class.MyExtensions.TextBoxIsEmpty(System.Windows.Forms.TextBox, System.Windows.Forms.ErrorProvider)' and 'DominateVehicle.Class.MyExtensions.TextBoxIsEmpty(System.Windows.Forms.TextBox, System.Windows.Forms.ErrorProvider)' D: \Vechel_Dominate\a\DominateVehicle\frmDefectClass.cs 30 41 DominateVehicle
不知道添加用户控件和这个错误有什么关系? 如果我删除 UserControl,我的代码将无法工作并且会收到错误消息。我该怎么办?
最佳答案
我也遇到了这个错误。
总是当我将项目中的控件添加到我的表单之一时,由于对所有扩展方法的调用不明确,我无法再编译。
最后我看到VS将我的项目的引用添加到同一个项目中,因此编译器遇到了问题。那么删除代码也无济于事,因为引用仍然存在。
我可以通过从我的项目中删除此引用来解决问题。也许这对其他人有帮助。
关于c# - 错误 130 - 以下方法或属性之间的调用不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14579533/