download; ebook; do ÂściÂągnięcia; pobieranie; pdf
Pokrewne
- Start
- Cyberpunk 2020 Reference Book 5.0
- Green, Sharon Brat 2 Queen Brat
- Leczenie GśÂ‚odowaniem [Aleksiej Suworin]
- Jakub Sprenger, Henryk Instytor Mlot na czarownice
- Sharif Abdel Azeem Kobieta w tradycji islamskiej i judeochrześÂ›cijaśÂ„skiej
- KochaśÂ„ska Luiza MeksykaśÂ„ski romans
- 635. Richmond Emma Z gśÂ‚owć… w chmurach
- Connell_Susan_ _Niespokojny_duch
- Ansley Vaughan Personal Statement
- Kuttner, Henry The Portal in the Picture
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- blox.htw.pl
[ Pobierz całość w formacie PDF ]
namespace body contain types by the same name, references to that name are considered ambiguous. In the
example
namespace N1
{
class A {}
}
namespace N2
{
class A {}
}
namespace N3
{
using N1;
using N2;
class B: A {} // Error, A is ambiguous
}
both N1 and N2 contain a member A, and because N3 imports both, referencing A in N3 is an error. In this
situation, the conflict can be resolved either through qualification of references to A, or by introducing a using-
alias-directive that picks a particular A. For example:
namespace N3
{
using N1;
using N2;
using A = N1.A;
class B: A {} // A means N1.A
}
Like a using-alias-directive, a using-namespace-directive does not contribute any new members to the
underlying declaration space of the compilation unit or namespace, but rather affects only the compilation unit
or namespace body in which it appears.
160 Copyright Microsoft Corporation 1999-2000. All Rights Reserved.
Chapter 9 Namespaces
The namespace-name referenced by a using-namespace-directive is resolved in the same way as the namespace-
or-type-name referenced by a using-alias-directive. Thus, using-namespace-directives in the same compilation
unit or namespace body do not affect each other and can be written in any order.
9.4 Namespace members
A namespace-member-declaration is either a namespace-declaration (§9.2) or a type-declaration (§9.5).
namespace-member-declarations:
namespace-member-declaration
namespace-member-declarations namespace-member-declaration
namespace-member-declaration:
namespace-declaration
type-declaration
A compilation unit or a namespace body can contain namespace-member-declarations, and such declarations
contribute new members to the underlying declaration space of the containing compilation unit or namespace
body.
9.5 Type declarations
A type-declaration is either a class-declaration (§10.1), a struct-declaration (§11.1), an interface-declaration
(§13.1), an enum-declaration (§14.1), or a delegate-declaration (§15.1).
type-declaration:
class-declaration
struct-declaration
interface-declaration
enum-declaration
delegate-declaration
A type-declaration can occur as a top-level declaration in a compilation unit or as a member declaration within a
namespace, class, or struct.
When a type declaration for a type T occurs as a top-level declaration in a compilation unit, the fully qualified
name of the newly declared type is simply T. When a type declaration for a type T occurs within a namespace,
class, or struct, the fully qualified name of the newly declared type is N.T, where N is the fully qualified name of
the containing namespace, class, or struct.
A type declared within a class or struct is called a nested type (§10.2.6).
The permitted access modifiers and the default access for a type declaration depend on the context in which the
declaration takes place (§3.3.1):
" Types declared in compilation units or namespaces can have public or internal access. The default is
internal access.
" Types declared in classes can have public, protected internal, protected, internal, or private
access. The default is private access.
" Types declared in structs can have public, internal, or private access. The default is private access.
Copyright Microsoft Corporation 1999-2000. All Rights Reserved. 161
Chapter 10 Classes
10. Classes
A class is a data structure that contains data members (constants, fields, and events), function members
(methods, properties, indexers, operators, constructors, and destructors), and nested types. Class types support
inheritance, a mechanism whereby derived classes can extend and specialize base classes.
10.1 Class declarations
A class-declaration is a type-declaration (§9.5) that declares a new class.
class-declaration:
attributesopt class-modifiersopt class identifier class-baseopt class-body ;opt
A class-declaration consists of an optional set of attributes (§17), followed by an optional set of class-modifiers
(§10.1.1), followed by the keyword class and an identifier that names the class, followed by an optional class-
base specification (§10.1.2), followed by a class-body (§10.1.3), optionally followed by a semicolon.
10.1.1 Class modifiers
A class-declaration may optionally include a sequence of class modifiers:
class-modifiers:
class-modifier
class-modifiers class-modifier
class-modifier:
new
public
protected
internal
private
abstract
sealed
It is an error for the same modifier to appear multiple times in a class declaration.
The new modifier is only permitted on nested classes. It specifies that the class hides an inherited member by the
same name, as described in §10.2.2.
The public, protected, internal, and private modifiers control the accessibility of the class. Depending
on the context in which the class declaration occurs, some of these modifiers may not be permitted (§3.3.1).
The abstract and sealed modifiers are discussed in the following sections.
10.1.1.1 Abstract classes
The abstract modifier is used to indicate that a class is incomplete and intended only to be a base class of
other classes. An abstract class differs from a non-abstract class is the following ways:
" An abstract class cannot be instantiated, and it is an error to use the new operator on an abstract class. While
it is possible to have variables and values whose compile-time types are abstract, such variables and values
will necessarily either be null or contain references to instances of non-abstract classes derived from the
abstract types.
" An abstract class is permitted (but not required) to contain abstract methods and accessors.
Copyright Microsoft Corporation 1999-2000. All Rights Reserved. 163
C# LANGUAGE REFERENCE
" An abstract class cannot be sealed.
When a non-abstract class is derived from an abstract class, the non-abstract class must include actual
implementations of all inherited abstract methods and accessors. Such implementations are provided by
overriding the abstract methods and accessors. In the example
abstract class A
{
public abstract void F();
}
abstract class B: A
{
public void G() {}
}
class C: B
{
public override void F() {
// actual implementation of F
}
}
the abstract class A introduces an abstract method F. Class B introduces an additional method G, but doesn t
provide an implementation of F. B must therefore also be declared abstract. Class C overrides F and provides an
actual implementation. Since there are no outstanding abstract methods or accessors in C, C is permitted (but not
required) to be non-abstract.
10.1.1.2 Sealed classes
[ Pobierz całość w formacie PDF ]