Can I have two identical function names with the same parameters, but with a different value.
For instance:
public void test(string name) public void test(string age)
Thank.
No, you can’t. The signature is no different - no matter what parameter names are.
Methods are declared in a class or structure, indicating the access level, such as public or private, optional modifiers, such as abstract or private, return value, method name, and any method parameters. These parts together are the signature of the method.http://msdn.microsoft.com/en-us/library/ms173114.aspx
Methods are declared in a class or structure, indicating the access level, such as public or private, optional modifiers, such as abstract or private, return value, method name, and any method parameters. These parts together are the signature of the method.
http://msdn.microsoft.com/en-us/library/ms173114.aspx
, , . , ? , , - int, .
int
, . ( , Objective C 1) .
(, ) , . params, .
</" > 1 , .
, , , , .
.
, ? .
, :
public void test(string name = null, string age = null) { if (name != null) { // Do something } else if (age != null) { // Do something else } }
And you can call this method as follows:
test(name: "John"); test(age: "30");
Not very clean, but still useful.
No - the compiler throws an error, because the compiler parameters are used to determine which method to call, and not the return type.
NO.
OVERLOADED FUNCTION must have a different SIGNATURE . that is, the arguments must be different, either in terms of the number of arguments, or with the order of the various arguments of the data types.