Ambiguity between Static and Instance Code

I have two items in my class: One is a public property, and the other is a static method that takes a parameter.

I really do not understand why Visual Studio 2010 is unable to see the difference between these two items.

Could someone explain this one to me?

Here is the code:

public bool IsShipped {
  get {
    #region ' Test Code '
    if (!String.IsNullOrEmpty(TrailerNo) || (TruckDate != Global.NODATE)) {
      return true;
    }
    #endregion
    return false;
  }
}

public static bool IsShipped(string boxNumber) {
  var array = GetCrate(boxNumber);
  if (array != null) {
    foreach (var item in array) {
      if (item.IsShipped) {
        return true;
      }
    }
  }
  return false;
}

Here is the error:

Error 1 Ambiguity between 'AcpClasses.AcpPackNShip.IsShipped' and 'AcpClasses.AcpPackNShip.IsShipped(string)' C:\Users\cp-jpool\My Projects\VS\Live\Common\Classes\AcpPackShip.cs 242 20 CoilPC

Answers


It's possible to refer to a method as a delegate, not just by calling it. For example, the following could would be valid use of the method:

Func<string, bool> myFunction = item.IsShipped;

Given that the method doesn't need to be actually called with parenthesis, there is no way of determining if item.IsShipped is supposed to refer to the method group for IsShipped or to be the property IsShipped.

Even if it were allowed, it would be a point likely to result in confusion. It would be preferable from a code maintenance perspective to have different names for the property/method, even if the compiler were somehow smart enough to know which one to use when (or worse, if it just picked one arbitrarily).


Need Your Help

How to Slide or Move this Set of Divs

javascript jquery css

I have a set of seven div's with the following properties:

Is it ever reasonable to do computations outside of main in an OpenGL shader?

opengl-es glsl webgl

I have some vertex shader code somewhat like the following (this is a bit of simplified example):