oop - C# compiler ignores duplicated parameter name in constructor -


i'm not sure why happening - hoping can explain it!

i have base class called baserequest in it:

protected int cartnumber; 

i have derived class, inherits baserequest. has public field , constructor follows:

public int currentcartnumber;  public extendedbaserequest(int cartnumber) {    currentcartnumber = cartnumber; } 

yes, know it's bit silly have parameter same name protected field in base class, didn't notice until now!

this compiles , runs, public currentcartnumber value in derived class not set uses value base class, 0 initialised.

shouldn't compiler moan because declaration of cartnumber in constructor's signature has same name 1 in base?

looking forward hearing you.

your analysis of what's happening incorrect. there's else going on here.

are sure you're not passing 0 constructor?

the unqualified cartnumber refer parameter. inherited field need qualified this or base.

in code shown in question, statement currentcartnumber = cartnumber assign value of cartnumber parameter currentcartnumber field.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -