c# - Criteria For Calling Two Methods Overloaded Methods? -
i've seen in c# specifications rules overloaded method gets used in call, can't seem find on criteria needs satisfied method overloaded method.
here shot @ it. please let me know if see problems it:
this not take access modifiers or generics consideration (i'm still noob working way through c# book)
consider 2 methods
- make sure both methods have correct formal parameter lists
- treat optional parameters mandatory parameters
- treat params 1 mandatory parameter type type of params array
- we have 2 lists of mandatory parameters
- (p1, p2, p3, p4) , (q1, q2, q3, q4)
- p1 , q1, p2 , q2, … parameter pairs
- to overloaded methods, 2 must have same name different parameter list
one of these must false
- same number of parameters
- each parameter pair must have same type
- each parameter pair must both have parameter-modifier or both not have parameter modifier.
example: method(ref int a) , method(out int a) not overloaded methods
- both 1 parameter
- both int
- both have parameter modifier
normally "method overloading" refers methods same name (including +/- operators) different arguments.
the term "overloaded" not strictly defined mean specific in c# language (unlike "method signature"). closes place definition section "3.6 signatures , overloading" of c# 4.0 specification:
signatures enabling mechanism overloading of members in classes, structs, , interfaces:
overloading of methods permits class, struct, or interface declare multiple methods same name, provided signatures unique within class, struct, or interface.
overloading of instance constructors permits class or struct declare multiple instance constructors, provided signatures unique within class or struct.
overloading of indexers permits class, struct, or interface declare multiple indexers, provided signatures unique within class, struct, or interface.
overloading of operators permits class or struct declare multiple operators same name, provided signatures unique within class or struct.
Comments
Post a Comment