NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Property Declaration

Properties are an extension of fields and are accessed using the same syntax. Unlike fields, properties do not designate storage locations. Instead, properties have accessors that read, write, or compute their values.

Property declaration takes one of the following forms:

[attributes] [modifiers] type identifier {accessor declaration}
[attributes] [modifiers] type interface-type.identifier {accessor declaration}

where:

attributes (Optional)
Additional declarative information. For more information on attributes and attribute classes, see C# Attributes.
modifiers (Optional)
The allowed modifiers are new, static, virtual, abstract, override, and a valid combination of the four access modifiers.
type
The property type, which must be at least as accessible as the property itself. For more information on accessibility levels, see Access Modifiers.
identifier
The property name. For more information on interface member implementation, see interface.
accessor-declaration
Declaration of the property accessors, which are used to read and write the property.
interface-type
The interface in a fully-qualified property name. See Interface Properties.

Remarks

Example

This example demonstrates instance, static, and read-only properties. It accepts the name of the employee from the keyboard, increments numberOfEmployees by 1, and displays the Employee name and number.

// Properties
using System;
public class Employee {
   public static int numberOfEmployees;
   private static int counter;
   private string name;
   // A read-write instance property:
   public string Name {
      get {
         return name; 
      }
      set { 
         name = value; 
      }
   }
   // A read-only static property:
   public static int Counter {
      get {
         return counter; 
      }
   }
   // Constructor:
   public Employee() {
      // Calculate the employee’s number:
      counter = ++counter + numberOfEmployees;
   }
}
public class MainClass {
   public static void Main() {
      Employee.numberOfEmployees = 100;
      Employee e1 = new Employee();
      e1.Name = "Claude Vige";  
      Console.WriteLine("Employee number: {0}", Employee.Counter);
      Console.WriteLine("Employee name: {0}", e1.Name);
   }
}

Output

Employee number: 101
Employee name: Claude Vige

See Also

Accessors | Indexers | Properties