what is a member vs. a property

后端 未结 9 2195
灰色年华
灰色年华 2020-12-15 03:39

A friend who is new to OO programming asked me the difference between a Member and Property, and I was ashamed to admit that I couldn\'t give him a good answer. Since proper

9条回答
  •  半阙折子戏
    2020-12-15 04:12

    A property is one kind of member. Others might be constructors, methods, fields, nested types, conversions, indexers etc - depending on the language/platform, of course. A lot of the time the exact meaning of terminology depends on the context.

    To give a C#-specific definition, from the C# 3.0 spec, section 1.6.1:

    The following table provides an overview of the kinds of members a class can contain.
    (Rows for...)

    • Constants
    • Fields
    • Methods
    • Properties
    • Indexers
    • Events
    • Operators
    • Constructors
    • Destructors
    • Types

    Note that that's members of a class. Different "things" have different kinds of members - in C#, an interface can't have a field as a member, for example.

提交回复
热议问题