Creating Type Members

After you have created a type in a class diagram, you can add members to it and configure them. For information about adding members, see How to: Create a Member. For information about modifying (configuring) members, see How to: Modify Type Members.

Each type that can be represented on a class diagram can contain specific kinds of members. The following table describes which types can contain which members:

Type

Members it can contain

Class

method, property (for C# and Visual Basic), field, event (for C# and Visual Basic), constructor (method), destructor (method), constant

Enum

member

Struct

method, property (for C# and Visual Basic) field, event (for C# and Visual Basic), constructor (method), constant

Interface

method, property, event (for C# and Visual Basic)

Delegate

parameter

Note

The only type for which you can specify parameters is delegate. You can specify parameters for methods, which in turn can be added to the types for class, struct, and interface; for more information, see How to: Add a Parameter to a Method.

Auto-Implemented Properties (C#)

Note

This feature is available in Visual C# only.

Auto-implemented properties make property declaration more concise when no additional logic is required in the property's get and set accessors. When you declare a property such as the following, the compiler creates a private, anonymous field that you can access only through the property's get and set accessors. The following example shows a simple class that has some auto-implemented properties:

public class Contact
{
   public string Name { get; set; }
   public string Address { get; set; }
   public int ContactNumber { get; set; }
   // If the set accessor is private, ID is a read-only property.
   public int ID { get; private set; }
}

Note that you can create a read-only auto-implemented property by giving it a private set accessor, as is done with IDNumber earlier.

If you specify Display Full Signature, the Class Diagram displays the signature of the above as follows:

Name { get; set; } string

Address { get; set; } string

ContactNumber { get; set; } int

To display the full signature, from the Class Diagram menu, select Change Members Format, and then click Display Full Signature.

For more information about auto-implemented properties, see:

Auto-Implemented Properties (C# Programming Guide)

Extension Methods

Extension methods enable you to add methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method that you call as if they were instance methods on the extended type. For client code written in C# and Visual Basic, there is no apparent difference between calling an extension method and the methods that are actually defined in a type.

For more information about extension methods, see:

Extension Methods (C# Programming Guide)

Extension Methods (Visual Basic)

See Also

Tasks

How to: Create a Member

How to: Modify Type Members

How to: Open the Class Details Window