Add a more functional (i.e. fewer-stubs) implementation of System.Data.Linq.
[mono.git] / mcs / docs / ecma334 / 18.3.4.xml
1 <?xml version="1.0"?>
2 <clause number="18.3.4" title="Default values">
3   <paragraph>As described in <hyperlink>12.2</hyperlink>, several kinds of variables are automatically initialized to their default value when they are created. For variables of class types and other reference types, this default value is null. However, since structs are value types that cannot be null, the default value of a struct is the value produced by setting all value type fields to their default value and all reference type fields to null. </paragraph>
4   <paragraph>
5     <example>[Example: Referring to the Point struct declared above, the example <code_example><![CDATA[
6 Point[] a = new Point[100];  
7 ]]></code_example>initializes each Point in the array to the value produced by setting the x and y fields to zero. end example]</example>
8   </paragraph>
9   <paragraph>The default value of a struct corresponds to the value returned by the default constructor of the struct (<hyperlink>11.1.1</hyperlink>). Unlike a class, a struct is not permitted to declare a parameterless instance constructor. Instead, every struct implicitly has a parameterless instance constructor, which always returns the value that results from setting all value type fields to their default value and all reference type fields to null. </paragraph>
10   <paragraph>
11     <note>[Note: Structs should be designed to consider the default initialization state a valid state. In the example <code_example><![CDATA[
12 using System;  
13 struct KeyValuePair  
14 {  
15    string key;  
16    string value;  
17    public KeyValuePair(string key, string value) {  
18       if (key == null || value == null) throw new ArgumentException();  
19       this.key = key;  
20       this.value = value;  
21    }  
22 }  
23 ]]></code_example>the user-defined instance constructor protects against null values only where it is explicitly called. In cases where a KeyValuePair variable is subject to default value initialization, the key and value fields will be null, and the struct must be prepared to handle this state. end note]</note>
24   </paragraph>
25 </clause>