0

助けて明確にしてください...なぜエラーが発生したのですか?

class Program
{
    static void Main(string[] args)
    {       

    }

    public int GetNames(int id)
    {
        return id;
    }

    public float GetNames(int id)
    {
        return (float)id;
    }

    public String GetNames(string id)
    {
        return id;
    }
}
4

1 に答える 1

11

You can't have methods which have same signature. Return value is not a part of method's signature. Signature defined by method name and input parameters. So you have two methods with same signature:

GetNames(int)

See Methods article on msdn

A return type of a method is not part of the signature of the method for the purposes of method overloading.

Solution - make signatures different (rename methods, change parameter type of method, or change parameters number)

于 2013-02-12T11:58:05.200 に答える