c# - Variable scope at the same source file in partial classes -


is there anyway reuse method/variable name in partial classes?

something internal defines variable scope @ assembly level time @ source file level. can use same name in code file , variable available other members @ same code (*.cs) file.

is there anyway reuse method/variable name in partial classes?

no, because partial classes mean actual class split amongst more 1 file. @ compile time combined single class, , same rules apply does.

i don't know specifics of trying do, suspect have 2 different classes , have 1 inherit other. mark methods etc. internal instead of private , subclass can see them in same class.

if absolutely need use same variable name in subclass, can use new key word: new string foo = "this new string."; ignore old foo string in base class , use 1 have redeclared.

from c# 4.0 spec:

with exception of partial methods (§10.2.7), set of members of type declared in multiple parts union of set of members declared in each part. bodies of parts of type declaration share same declaration space (§3.3), , scope of each member (§3.7) extends bodies of parts. accessibility domain of member includes parts of enclosing type; private member declared in 1 part freely accessible part. compile-time error declare same member in more 1 part of type, unless member type partial modifier.

partial class {     int x;                      // error, cannot declare x more once     partial class inner     // ok, inner partial type     {         int y;     } } partial class {     int x;                      // error, cannot declare x more once     partial class inner     // ok, inner partial type     {         int z;     } } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -