- 浏览: 520763 次
- 性别:
- 来自: 河北
最新评论
-
zrong:
已经支持了。
杂谈:倘若flash支持JPEG XR格式? -
蓝月儿:
anr是这么解释的呀。。。一次面试的笔试题,竟然都不知道是这样 ...
什么是ANR 如何避免它? -
hymer2011:
这是纯jsp的还是基于ssh的?
jsp网上商城源码 -
敲敲大葱头:
好文章,学习了
Android-SDK SearchableDemo--浮动搜索框(SearchManager) -
overkill:
你好,我在使用InstallAnywhere的silent安装 ...
InstallAnyWhere学习笔记 ( by quqi99 )
The members of a class consist of the members introduced by its
class-member-declarations and the members
inherited from the direct base class.
class-member-declarations:
class-member-declaration
class-member-declarations class-member-declaration
class-member-declaration:
constant-declaration
field-declaration
method-declaration
property-declaration
event-declaration
indexer-declaration
operator-declaration
constructor-declaration
destructor-declaration
static-constructor-declaration
type-declaration
The members of a class are divided into the following categories:
? Constants, which represent constant values associated with that class (§17
.3).
? Fields, which are the variables of that class (§17.4).
? Methods, which implement the computations and actions that can be
performed by that class (§17.5).
? Properties, which define named characteristics and the actions associated
with reading and writing those
characteristics (§17.6).
? Events, which define notifications that can be generated by that class (§1
7.7).
? Indexers, which permit instances of that class to be indexed in the same
way as arrays (§17.8).
? Operators, which define the expression operators that can be applied to
instances of that class (§17.9).
? Instance constructors, which implement the actions required to initialize
instances of that class (§17.10)
? Destructors, which implement the actions to be performed before instances
of that class are permanently
discarded (§17.12).
? Static constructors, which implement the actions required to initialize
that class itself (§17.11).
? Types, which represent the types that are local to that class (§16.5).
Members that can contain executable code are collectively known as the
function members of the class. The
function members of a class are the methods, properties, events, indexers,
operators, instance constructors,
destructors, and static constructors of that class.
A class-declaration creates a new declaration space (§10.3), and the
class-member-declarations immediately
contained by the class-declaration introduce new members into this
declaration space. The following rules apply
to class-member-declarations:
? Instance constructors, destructors, and static constructors must have the
same name as the immediately
enclosing class. All other members must have names that differ from the
name of the immediately enclosing
class.
? The name of a constant, field, property, event, or type must differ from
the names of all other members
declared in the same class.
? The name of a method must differ from the names of all other non-methods
declared in the same class. In
addition, the signature (§10.6) of a method must differ from the
signatures of all other methods declared in
Chapter 17 Classes
213
the same class, and two methods declared in the same class may not have
signatures that differ solely by ref
and out.
? The signature of an instance constructor must differ from the signatures
of all other instance constructors
declared in the same class, and two constructors declared in the same class
may not have signatures that
differ solely by ref and out.
? The signature of an indexer must differ from the signatures of all other
indexers declared in the same class.
? The signature of an operator must differ from the signatures of all other
operators declared in the same class.
The inherited members of a class (§17.2.1) are not part of the declaration
space of a class. [Note: Thus, a derived
class is allowed to declare a member with the same name or signature as an
inherited member (which in effect
hides the inherited member). end note]
17.2.1 Inheritance
A class inherits the members of its direct base class. Inheritance means
that a class implicitly contains all
members of its direct base class, except for the instance constructors,
destructors, and static constructors of the
base class. Some important aspects of inheritance are:
? Inheritance is transitive. If C is derived from B, and B is derived from
A, then C inherits the members
declared in B as well as the members declared in A.
? A derived class extends its direct base class. A derived class can add
new members to those it inherits, but it
cannot remove the definition of an inherited member.
? Instance constructors, destructors, and static constructors are not
inherited, but all other members are,
regardless of their declared accessibility (§10.5). However, depending on
their declared accessibility,
inherited members might not be accessible in a derived class.
? A derived class can hide (§10.7.1.2) inherited members by declaring new
members with the same name or
signature. However, hiding an inherited member does not remove that
member?it merely makes that
member inaccessible in the derived class.
? An instance of a class contains a set of all instance fields declared in
the class and its base classes, and an
implicit conversion (§13.1.4) exists from a derived class type to any of
its base class types. Thus, a reference
to an instance of some derived class can be treated as a reference to an
instance of any of its base classes.
? A class can declare virtual methods, properties, and indexers, and
derived classes can override the
implementation of these function members. This enables classes to exhibit
polymorphic behavior wherein the
actions performed by a function member invocation varies depending on the
run-time type of the instance
through which that function member is invoked.
17.2.2 The new modifier
A class-member-declaration is permitted to declare a member with the same
name or signature as an inherited
member. When this occurs, the derived class member is said to hide the base
class member. Hiding an inherited
member is not considered an error, but it does cause the compiler to issue
a warning. To suppress the warning,
the declaration of the derived class member can include a new modifier to
indicate that the derived member is
intended to hide the base member. This topic is discussed further in §10.7.1
.2.
If a new modifier is included in a declaration that doesn?t hide an
inherited member, a warning to that effect is
issued. This warning is suppressed by removing the new modifier.
17.2.3 Access modifiers
A class-member-declaration can have any one of the five possible kinds of
declared accessibility (§10.5.1):
public, protected internal, protected, internal, or private. Except for the
protected internal
combination, it is a compile-time error to specify more than one access
modifier. When a class-memberdeclaration
does not include any access modifiers, private is assumed.
C# LANGUAGE SPECIFICATION
214
17.2.4 Constituent types
Types that are used in the declaration of a member are called the
constituent types of that member. Possible
constituent types are the type of a constant, field, property, event, or
indexer, the return type of a method or
operator, and the parameter types of a method, indexer, operator, or
instance constructor. The constituent types of
a member must be at least as accessible as that member itself (§10.5.4).
17.2.5 Static and instance members
Members of a class are either static members or instance members. [Note:
Generally speaking, it is useful to
think of static members as belonging to classes and instance members as
belonging to objects (instances of
classes). end note]
When a field, method, property, event, operator, or constructor declaration
includes a static modifier, it
declares a static member. In addition, a constant or type declaration
implicitly declares a static member. Static
members have the following characteristics:
? When a static member is referenced in a member-access (§14.5.4) of the
form E.M, E must denote a type that
has a member M. It is a compile-time error for E to denote an instance.
? A static field identifies exactly one storage location. No matter how
many instances of a class are created,
there is only ever one copy of a static field.
? A static function member (method, property, event, operator, or
constructor) does not operate on a specific
instance, and it is a compile-time error to refer to this in such a
function member.
When a field, method, property, event, indexer, constructor, or destructor
declaration does not include a static
modifier, it declares an instance member. (An instance member is sometimes
called a non-static member.)
Instance members have the following characteristics:
? When an instance member is referenced in a member-access (§14.5.4) of
the form E.M, E must denote an
instance of a type that has a member M. It is a compile-time error for E to
denote a type.
? Every instance of a class contains a separate set of all instance fields
of the class.
? An instance function member (method, property, indexer, instance
constructor, or destructor) operates on a
given instance of the class, and this instance can be accessed as this (§14.
5.7).
[Example: The following example illustrates the rules for accessing static
and instance members:
class Test
{
int x;
static int y;
void F() {
x = 1; // Ok, same as this.x = 1
y = 1; // Ok, same as Test.y = 1
}
static void G() {
x = 1; // Error, cannot access this.x
y = 1; // Ok, same as Test.y = 1
}
static void Main() {
Test t = new Test();
t.x = 1; // Ok
t.y = 1; // Error, cannot access static member through instance
Test.x = 1; // Error, cannot access instance member through type
Test.y = 1; // Ok
}
}
The F method shows that in an instance function member, a simple-name (§14.5
.2) can be used to access both
instance members and static members. The G method shows that in a static
function member, it is a compile-time
error to access an instance member through a simple-name. The Main method
shows that in a member-access
Chapter 17 Classes
215
(§14.5.4), instance members must be accessed through instances, and static
members must be accessed through
types. end example]
17.2.6 Nested types
A type declared within a class or struct is called a nested type. A type
that is declared within a compilation unit
or namespace is called a non-nested type. [Example: In the following
example:
using System;
class A
{
class B
{
static void F() {
Console.WriteLine("A.B.F");
}
}
}
class B is a nested type because it is declared within class A, and class A
is a non-nested type because it is
declared within a compilation unit. end example]
17.2.6.1 Fully qualified name
The fully qualified name (§10.8.1) for a nested type is S.N where S is the
fully qualified name of the type in
which type N is declared.
17.2.6.2 Declared accessibility
Non-nested types can have public or internal declared accessibility and
they have internal declared accessibility
by default. Nested types can have these forms of declared accessibility
too, plus one or more additional forms of
declared accessibility, depending on whether the containing type is a class
or struct:
? A nested type that is declared in a class can have any of five forms of
declared accessibility (public, protected
internal, protected, internal, or private) and, like other class members,
defaults to private declared
accessibility.
? A nested type that is declared in a struct can have any of three forms of
declared accessibility (public,
internal, or private) and, like other struct members, defaults to private
declared accessibility.
[Example: The example
public class List
{
// Private data structure
private class Node
{
public object Data;
public Node Next;
public Node(object data, Node next) {
this.Data = data;
this.Next = next;
}
}
private Node first = null;
private Node last = null;
// Public interface
public void AddToFront(object o) {?}
public void AddToBack(object o) {?}
public object RemoveFromFront() {?}
public object AddToFront() {?}
public int Count { get {?} }
}
declares a private nested class Node. end example]
C# LANGUAGE SPECIFICATION
216
17.2.6.3 Hiding
A nested type may hide (§10.7.1.1) a base member. The new modifier is
permitted on nested type declarations so
that hiding can be expressed explicitly. [Example: The example
using System;
class Base
{
public static void M() {
Console.WriteLine("Base.M");
}
}
class Derived: Base
{
new public class M
{
public static void F() {
Console.WriteLine("Derived.M.F");
}
}
}
class Test
{
static void Main() {
Derived.M.F();
}
}
shows a nested class M that hides the method M defined in Base. end example]
17.2.6.4 this access
A nested type and its containing type do not have a special relationship
with regard to this-access (§14.5.7).
Specifically, this within a nested type cannot be used to refer to instance
members of the containing type. In
cases where a nested type needs access to the instance members of its
containing type, access can be provided by
providing the this for the instance of the containing type as a constructor
argument for the nested type.
[Example: The following example
using System;
class C
{
int i = 123;
public void F() {
Nested n = new Nested(this);
n.G();
}
public class Nested
{
C this_c;
public Nested(C c) {
this_c = c;
}
public void G() {
Console.WriteLine(this_c.i);
}
}
}
class Test
{
static void Main() {
C c = new C();
c.F();
}
}
Chapter 17 Classes
217
shows this technique. An instance of C creates an instance of Nested, and
passes its own this to Nested’s
constructor in order to provide subsequent access to C’s instance members.
end example]
17.2.6.5 Access to private and protected members of the containing type
A nested type has access to all of the members that are accessible to its
containing type, including members of the
containing type that have private and protected declared accessibility.
[Example: The example
using System;
class C
{
private static void F() {
Console.WriteLine("C.F");
}
public class Nested
{
public static void G() {
F();
}
}
}
class Test
{
static void Main() {
C.Nested.G();
}
}
shows a class C that contains a nested class Nested. Within Nested, the
method G calls the static method F
defined in C, and F has private declared accessibility. end example]
A nested type also may access protected members defined in a base type of
its containing type. [Example: In the
example
using System;
class Base
{
protected void F() {
Console.WriteLine("Base.F");
}
}
class Derived: Base
{
public class Nested
{
public void G() {
Derived d = new Derived();
d.F(); // ok
}
}
}
class Test
{
static void Main() {
Derived.Nested n = new Derived.Nested();
n.G();
}
}
the nested class Derived.Nested accesses the protected method F defined in
Derived’s base class, Base, by
calling through an instance of Derived. end example]
17.2.7 Reserved member names
To facilitate the underlying C# runtime implementation, for each source
member declaration that is a property,
event, or indexer, the implementation must reserve two method signatures
based on the kind of the member
C# LANGUAGE SPECIFICATION
218
declaration, its name, and its type (§17.2.7.1, §17.2.7.2, §17.2.7.3).
It is a compile-time error for a program to
declare a member whose signature matches one of these reserved signatures,
even if the underlying runtime
implementation does not make use of these reservations.
The reserved names do not introduce declarations, thus they do not
participate in member lookup. However, a
declaration?s associated reserved method signatures do participate in
inheritance (§17.2.1), and can be hidden
with the new modifier (§17.2.2).
[Note: The reservation of these names serves three purposes:
1. To allow the underlying implementation to use an ordinary identifier as
a method name for get or set
access to the C# language feature.
2. To allow other languages to interoperate using an ordinary identifier as
a method name for get or set
access to the C# language feature.
3. To help ensure that the source accepted by one conforming compiler is
accepted by another, by making
the specifics of reserved member names consistent across all C#
implementations.
end note]
The declaration of a destructor (§17.12) also causes a signature to be
reserved (§17.2.7.4).
17.2.7.1 Member Names Reserved for Properties
For a property P (§17.6) of type T, the following signatures are reserved:
T get_P();
void set_P(T value);
Both signatures are reserved, even if the property is read-only or
write-only.
[Example: In the example
using System;
class A
{
public int P {
get { return 123; }
}
}
class B: A
{
new public int get_P() {
return 456;
}
new public void set_P(int value) {
}
}
class Test
{
static void Main() {
B b = new B();
A a = b;
Console.WriteLine(a.P);
Console.WriteLine(b.P);
Console.WriteLine(b.get_P());
}
}
a class A defines a read-only property P, thus reserving signatures for
get_P and set_P methods. A class B
derives from A and hides both of these reserved signatures. The example
produces the output:
123
123
456
end example]
Chapter 17 Classes
219
17.2.7.2 Member Names Reserved for Events
For an event E (§17.7) of delegate type T, the following signatures are
reserved:
void add_E(T handler);
void remove_E(T handler);
17.2.7.3 Member Names Reserved for Indexers
For an indexer (§17.8) of type T with parameter-list L, the following
signatures are reserved:
T get_Item(L);
void set_Item(L, T value);
Both signatures are reserved, even if the indexer is read-only or
write-only.
17.2.7.4 Member Names Reserved for Destructors
For a class containing a destructor (§17.12), the following signature is
reserved:
void Finalize();
class-member-declarations and the members
inherited from the direct base class.
class-member-declarations:
class-member-declaration
class-member-declarations class-member-declaration
class-member-declaration:
constant-declaration
field-declaration
method-declaration
property-declaration
event-declaration
indexer-declaration
operator-declaration
constructor-declaration
destructor-declaration
static-constructor-declaration
type-declaration
The members of a class are divided into the following categories:
? Constants, which represent constant values associated with that class (§17
.3).
? Fields, which are the variables of that class (§17.4).
? Methods, which implement the computations and actions that can be
performed by that class (§17.5).
? Properties, which define named characteristics and the actions associated
with reading and writing those
characteristics (§17.6).
? Events, which define notifications that can be generated by that class (§1
7.7).
? Indexers, which permit instances of that class to be indexed in the same
way as arrays (§17.8).
? Operators, which define the expression operators that can be applied to
instances of that class (§17.9).
? Instance constructors, which implement the actions required to initialize
instances of that class (§17.10)
? Destructors, which implement the actions to be performed before instances
of that class are permanently
discarded (§17.12).
? Static constructors, which implement the actions required to initialize
that class itself (§17.11).
? Types, which represent the types that are local to that class (§16.5).
Members that can contain executable code are collectively known as the
function members of the class. The
function members of a class are the methods, properties, events, indexers,
operators, instance constructors,
destructors, and static constructors of that class.
A class-declaration creates a new declaration space (§10.3), and the
class-member-declarations immediately
contained by the class-declaration introduce new members into this
declaration space. The following rules apply
to class-member-declarations:
? Instance constructors, destructors, and static constructors must have the
same name as the immediately
enclosing class. All other members must have names that differ from the
name of the immediately enclosing
class.
? The name of a constant, field, property, event, or type must differ from
the names of all other members
declared in the same class.
? The name of a method must differ from the names of all other non-methods
declared in the same class. In
addition, the signature (§10.6) of a method must differ from the
signatures of all other methods declared in
Chapter 17 Classes
213
the same class, and two methods declared in the same class may not have
signatures that differ solely by ref
and out.
? The signature of an instance constructor must differ from the signatures
of all other instance constructors
declared in the same class, and two constructors declared in the same class
may not have signatures that
differ solely by ref and out.
? The signature of an indexer must differ from the signatures of all other
indexers declared in the same class.
? The signature of an operator must differ from the signatures of all other
operators declared in the same class.
The inherited members of a class (§17.2.1) are not part of the declaration
space of a class. [Note: Thus, a derived
class is allowed to declare a member with the same name or signature as an
inherited member (which in effect
hides the inherited member). end note]
17.2.1 Inheritance
A class inherits the members of its direct base class. Inheritance means
that a class implicitly contains all
members of its direct base class, except for the instance constructors,
destructors, and static constructors of the
base class. Some important aspects of inheritance are:
? Inheritance is transitive. If C is derived from B, and B is derived from
A, then C inherits the members
declared in B as well as the members declared in A.
? A derived class extends its direct base class. A derived class can add
new members to those it inherits, but it
cannot remove the definition of an inherited member.
? Instance constructors, destructors, and static constructors are not
inherited, but all other members are,
regardless of their declared accessibility (§10.5). However, depending on
their declared accessibility,
inherited members might not be accessible in a derived class.
? A derived class can hide (§10.7.1.2) inherited members by declaring new
members with the same name or
signature. However, hiding an inherited member does not remove that
member?it merely makes that
member inaccessible in the derived class.
? An instance of a class contains a set of all instance fields declared in
the class and its base classes, and an
implicit conversion (§13.1.4) exists from a derived class type to any of
its base class types. Thus, a reference
to an instance of some derived class can be treated as a reference to an
instance of any of its base classes.
? A class can declare virtual methods, properties, and indexers, and
derived classes can override the
implementation of these function members. This enables classes to exhibit
polymorphic behavior wherein the
actions performed by a function member invocation varies depending on the
run-time type of the instance
through which that function member is invoked.
17.2.2 The new modifier
A class-member-declaration is permitted to declare a member with the same
name or signature as an inherited
member. When this occurs, the derived class member is said to hide the base
class member. Hiding an inherited
member is not considered an error, but it does cause the compiler to issue
a warning. To suppress the warning,
the declaration of the derived class member can include a new modifier to
indicate that the derived member is
intended to hide the base member. This topic is discussed further in §10.7.1
.2.
If a new modifier is included in a declaration that doesn?t hide an
inherited member, a warning to that effect is
issued. This warning is suppressed by removing the new modifier.
17.2.3 Access modifiers
A class-member-declaration can have any one of the five possible kinds of
declared accessibility (§10.5.1):
public, protected internal, protected, internal, or private. Except for the
protected internal
combination, it is a compile-time error to specify more than one access
modifier. When a class-memberdeclaration
does not include any access modifiers, private is assumed.
C# LANGUAGE SPECIFICATION
214
17.2.4 Constituent types
Types that are used in the declaration of a member are called the
constituent types of that member. Possible
constituent types are the type of a constant, field, property, event, or
indexer, the return type of a method or
operator, and the parameter types of a method, indexer, operator, or
instance constructor. The constituent types of
a member must be at least as accessible as that member itself (§10.5.4).
17.2.5 Static and instance members
Members of a class are either static members or instance members. [Note:
Generally speaking, it is useful to
think of static members as belonging to classes and instance members as
belonging to objects (instances of
classes). end note]
When a field, method, property, event, operator, or constructor declaration
includes a static modifier, it
declares a static member. In addition, a constant or type declaration
implicitly declares a static member. Static
members have the following characteristics:
? When a static member is referenced in a member-access (§14.5.4) of the
form E.M, E must denote a type that
has a member M. It is a compile-time error for E to denote an instance.
? A static field identifies exactly one storage location. No matter how
many instances of a class are created,
there is only ever one copy of a static field.
? A static function member (method, property, event, operator, or
constructor) does not operate on a specific
instance, and it is a compile-time error to refer to this in such a
function member.
When a field, method, property, event, indexer, constructor, or destructor
declaration does not include a static
modifier, it declares an instance member. (An instance member is sometimes
called a non-static member.)
Instance members have the following characteristics:
? When an instance member is referenced in a member-access (§14.5.4) of
the form E.M, E must denote an
instance of a type that has a member M. It is a compile-time error for E to
denote a type.
? Every instance of a class contains a separate set of all instance fields
of the class.
? An instance function member (method, property, indexer, instance
constructor, or destructor) operates on a
given instance of the class, and this instance can be accessed as this (§14.
5.7).
[Example: The following example illustrates the rules for accessing static
and instance members:
class Test
{
int x;
static int y;
void F() {
x = 1; // Ok, same as this.x = 1
y = 1; // Ok, same as Test.y = 1
}
static void G() {
x = 1; // Error, cannot access this.x
y = 1; // Ok, same as Test.y = 1
}
static void Main() {
Test t = new Test();
t.x = 1; // Ok
t.y = 1; // Error, cannot access static member through instance
Test.x = 1; // Error, cannot access instance member through type
Test.y = 1; // Ok
}
}
The F method shows that in an instance function member, a simple-name (§14.5
.2) can be used to access both
instance members and static members. The G method shows that in a static
function member, it is a compile-time
error to access an instance member through a simple-name. The Main method
shows that in a member-access
Chapter 17 Classes
215
(§14.5.4), instance members must be accessed through instances, and static
members must be accessed through
types. end example]
17.2.6 Nested types
A type declared within a class or struct is called a nested type. A type
that is declared within a compilation unit
or namespace is called a non-nested type. [Example: In the following
example:
using System;
class A
{
class B
{
static void F() {
Console.WriteLine("A.B.F");
}
}
}
class B is a nested type because it is declared within class A, and class A
is a non-nested type because it is
declared within a compilation unit. end example]
17.2.6.1 Fully qualified name
The fully qualified name (§10.8.1) for a nested type is S.N where S is the
fully qualified name of the type in
which type N is declared.
17.2.6.2 Declared accessibility
Non-nested types can have public or internal declared accessibility and
they have internal declared accessibility
by default. Nested types can have these forms of declared accessibility
too, plus one or more additional forms of
declared accessibility, depending on whether the containing type is a class
or struct:
? A nested type that is declared in a class can have any of five forms of
declared accessibility (public, protected
internal, protected, internal, or private) and, like other class members,
defaults to private declared
accessibility.
? A nested type that is declared in a struct can have any of three forms of
declared accessibility (public,
internal, or private) and, like other struct members, defaults to private
declared accessibility.
[Example: The example
public class List
{
// Private data structure
private class Node
{
public object Data;
public Node Next;
public Node(object data, Node next) {
this.Data = data;
this.Next = next;
}
}
private Node first = null;
private Node last = null;
// Public interface
public void AddToFront(object o) {?}
public void AddToBack(object o) {?}
public object RemoveFromFront() {?}
public object AddToFront() {?}
public int Count { get {?} }
}
declares a private nested class Node. end example]
C# LANGUAGE SPECIFICATION
216
17.2.6.3 Hiding
A nested type may hide (§10.7.1.1) a base member. The new modifier is
permitted on nested type declarations so
that hiding can be expressed explicitly. [Example: The example
using System;
class Base
{
public static void M() {
Console.WriteLine("Base.M");
}
}
class Derived: Base
{
new public class M
{
public static void F() {
Console.WriteLine("Derived.M.F");
}
}
}
class Test
{
static void Main() {
Derived.M.F();
}
}
shows a nested class M that hides the method M defined in Base. end example]
17.2.6.4 this access
A nested type and its containing type do not have a special relationship
with regard to this-access (§14.5.7).
Specifically, this within a nested type cannot be used to refer to instance
members of the containing type. In
cases where a nested type needs access to the instance members of its
containing type, access can be provided by
providing the this for the instance of the containing type as a constructor
argument for the nested type.
[Example: The following example
using System;
class C
{
int i = 123;
public void F() {
Nested n = new Nested(this);
n.G();
}
public class Nested
{
C this_c;
public Nested(C c) {
this_c = c;
}
public void G() {
Console.WriteLine(this_c.i);
}
}
}
class Test
{
static void Main() {
C c = new C();
c.F();
}
}
Chapter 17 Classes
217
shows this technique. An instance of C creates an instance of Nested, and
passes its own this to Nested’s
constructor in order to provide subsequent access to C’s instance members.
end example]
17.2.6.5 Access to private and protected members of the containing type
A nested type has access to all of the members that are accessible to its
containing type, including members of the
containing type that have private and protected declared accessibility.
[Example: The example
using System;
class C
{
private static void F() {
Console.WriteLine("C.F");
}
public class Nested
{
public static void G() {
F();
}
}
}
class Test
{
static void Main() {
C.Nested.G();
}
}
shows a class C that contains a nested class Nested. Within Nested, the
method G calls the static method F
defined in C, and F has private declared accessibility. end example]
A nested type also may access protected members defined in a base type of
its containing type. [Example: In the
example
using System;
class Base
{
protected void F() {
Console.WriteLine("Base.F");
}
}
class Derived: Base
{
public class Nested
{
public void G() {
Derived d = new Derived();
d.F(); // ok
}
}
}
class Test
{
static void Main() {
Derived.Nested n = new Derived.Nested();
n.G();
}
}
the nested class Derived.Nested accesses the protected method F defined in
Derived’s base class, Base, by
calling through an instance of Derived. end example]
17.2.7 Reserved member names
To facilitate the underlying C# runtime implementation, for each source
member declaration that is a property,
event, or indexer, the implementation must reserve two method signatures
based on the kind of the member
C# LANGUAGE SPECIFICATION
218
declaration, its name, and its type (§17.2.7.1, §17.2.7.2, §17.2.7.3).
It is a compile-time error for a program to
declare a member whose signature matches one of these reserved signatures,
even if the underlying runtime
implementation does not make use of these reservations.
The reserved names do not introduce declarations, thus they do not
participate in member lookup. However, a
declaration?s associated reserved method signatures do participate in
inheritance (§17.2.1), and can be hidden
with the new modifier (§17.2.2).
[Note: The reservation of these names serves three purposes:
1. To allow the underlying implementation to use an ordinary identifier as
a method name for get or set
access to the C# language feature.
2. To allow other languages to interoperate using an ordinary identifier as
a method name for get or set
access to the C# language feature.
3. To help ensure that the source accepted by one conforming compiler is
accepted by another, by making
the specifics of reserved member names consistent across all C#
implementations.
end note]
The declaration of a destructor (§17.12) also causes a signature to be
reserved (§17.2.7.4).
17.2.7.1 Member Names Reserved for Properties
For a property P (§17.6) of type T, the following signatures are reserved:
T get_P();
void set_P(T value);
Both signatures are reserved, even if the property is read-only or
write-only.
[Example: In the example
using System;
class A
{
public int P {
get { return 123; }
}
}
class B: A
{
new public int get_P() {
return 456;
}
new public void set_P(int value) {
}
}
class Test
{
static void Main() {
B b = new B();
A a = b;
Console.WriteLine(a.P);
Console.WriteLine(b.P);
Console.WriteLine(b.get_P());
}
}
a class A defines a read-only property P, thus reserving signatures for
get_P and set_P methods. A class B
derives from A and hides both of these reserved signatures. The example
produces the output:
123
123
456
end example]
Chapter 17 Classes
219
17.2.7.2 Member Names Reserved for Events
For an event E (§17.7) of delegate type T, the following signatures are
reserved:
void add_E(T handler);
void remove_E(T handler);
17.2.7.3 Member Names Reserved for Indexers
For an indexer (§17.8) of type T with parameter-list L, the following
signatures are reserved:
T get_Item(L);
void set_Item(L, T value);
Both signatures are reserved, even if the indexer is read-only or
write-only.
17.2.7.4 Member Names Reserved for Destructors
For a class containing a destructor (§17.12), the following signature is
reserved:
void Finalize();
相关推荐
DevExpress 17.2是该系列的一个版本,发布于2017年,包含了丰富的控件集合和开发工具,旨在提升开发者的效率,提供美观且功能强大的用户界面。 在C#编程中,DevExpress 17.2提供了以下关键知识点: 1. **控件集合*...
candence17.2 支持win64位系统。
Devexpress 17.2破解文件,配合VS2017简直是如虎添翼,
Cadence公司发布的Allegro PCB设计工具17.2版本带来了多项改进和新功能,其中特别针对PCB设计的效率和质量进行了优化。本文将详细解读Allegro 17.2中文版新增的功能点。 首先,Cadence公司使***ro软件架构升级至64...
Cadence Allegro 17.2是一款用于电子设计的高级PCB(印刷电路板)设计软件,它是由Cadence公司开发的,这款软件在电子设计自动化(EDA)领域内具有广泛的应用。在Allegro 17.2版本中,Cadence公司对产品进行了多项...
这个17.2版本的中文语言包是专为开发者设计的,旨在帮助那些使用Devexpress组件的程序员更好地理解和操作其界面元素,尤其对于非英语背景的开发者来说,这是一个非常实用的资源。 Devexpress的17.2版本包含了多个...
版本17.2是DevExpress的一个特定发行版,包含了该时期最新的特性和改进。汉化资源则使得DevExpress的组件和功能更适合中文用户使用,避免了语言障碍,提高了开发效率。 在描述中提到的"官方网站下载,亲测可以",...
allegro17.2 11月补丁包S029。百度网盘下载Hotfix_SPB17.20.029_wint_1of1.exe
这个"DevExpress17.2汉化资源.rar"压缩包包含了DevExpress 17.2版本的相关资源,包括安装包和汉化文件,适用于那些需要在中文环境下开发应用的用户。 首先,我们来看"DevExpressDevExtreme-17.2.4.exe",这是一个...
Cadence设计系统公司于日前发布了其新的诚意大作Cadence SPB OrCAD Allegro 17.2-2016,该版本其为我们带来了一些全新易用特性。但是为了提高Cadence Allegro及OrCAD 17.0的仿真性能,Cadence 17.0将只支持64位版本...
版本17.2-AD19是针对Allegro的一个特定更新,提供了更先进的设计功能和与Altium Designer(简称AD)的互操作性。这个压缩包文件“Allegro 17.2-AD19.zip”可能包含了转换工具或教程,帮助用户将Allegro的PDB...
DevExpress 17.2组合: 安装包,破解包,中文语言包。 本程序仅限交流学习使用。
【Magisk v17.2.zip】是一款针对Android设备的著名系统级自定义模块管理工具,由著名的XDA开发者topjohnwu开发。Magisk的主要功能是允许用户在不破坏系统安全性的前提下进行深度定制,比如安装各种自定义模块、隐藏...
OrCAD-Capture-17.2-CV190905.7z more sizes more features
Devexpress 17.2 中文语言包 说明:从16.1最全的中文翻译包转过来的。本程序仅限交流学习使用,记得给个好评支持一下,多谢!
Cadence最新版,优化了软件性能,同步布线,但是不向下兼容低版本,请悉知
再多说几句:对比过更新的 17.4,还是17.2的 UI 比较熟悉,就是这个版本。感觉厂家过于追求新奇了,UI 设计上还是应当避免过于激进,容易扯着。另外,cadence 最新的 viewer 下载包要 九百多兆,太夸张了。
《OrCAD 17.2 Lite:电子设计自动化利器》 OrCAD 17.2 Lite是一款由Cadence Design Systems公司推出的轻量级电子设计自动化(EDA)软件,专为初学者和小型项目设计者提供。它包含了多个关键组件,如OrCAD Capture、...
2.打开17.2版本的PCB文件,执行Command>downrev17命令, 选择数据导出的目录(建议使用默认目录),然后执行导出。 3.打开Allegro16.6软件,执行Command>downrev17命令,选择上一步17.2数据导出的目录位置,然后进行导入...