Add a more functional (i.e. fewer-stubs) implementation of System.Data.Linq.
[mono.git] / mcs / docs / ecma334 / 8.2.xml
1 <?xml version="1.0"?>
2 <clause number="8.2" title="Types" informative="true">
3   <paragraph>C# supports two kinds of types: value types and reference types. Value types include simple types (e.g., <keyword>char</keyword>, <keyword>int</keyword>, and <keyword>float</keyword>), enum types, and struct types. Reference types include class types, interface types, delegate types, and array types. </paragraph>
4   <paragraph>Value types differ from reference types in that variables of the value types directly contain their data, whereas variables of the reference types store references to objects. With reference types, it is possible for two variables to reference the same object, and thus possible for operations on one variable to affect the object referenced by the other variable. With value types, the variables each have their own copy of the data, and it is not possible for operations on one to affect the other. </paragraph>
5   <paragraph>The example <code_example><![CDATA[
6 using System;  
7 class Class1  
8 {  
9    public int Value = 0;  
10 }  
11 class Test  
12 {  
13    static void Main() {  
14       int val1 = 0;  
15       int val2 = val1;  
16       val2 = 123;  
17       Class1 ref1 = new Class1();  
18       Class1 ref2 = ref1;  
19       ref2.Value = 123;  
20       Console.WriteLine("Values: {0}, {1}", val1, val2);  
21       Console.WriteLine("Refs: {0}, {1}", ref1.Value, ref2.Value);  
22    }  
23 }  
24 ]]></code_example>shows this difference. The output produced is <code_example><![CDATA[
25 Values: 0, 123  
26 Refs: 123, 123  
27 ]]></code_example></paragraph>
28   <paragraph>The assignment to the local variable val1 does not impact the local variable val2 because both local variables are of a value type (the type <keyword>int</keyword>) and each local variable of a value type has its own storage. In contrast, the assignment ref2.Value = 123; affects the object that both ref1 and ref2 reference. </paragraph>
29   <paragraph>The lines <code_example><![CDATA[
30 Console.WriteLine("Values: {0}, {1}", val1, val2);  
31 Console.WriteLine("Refs: {0}, {1}", ref1.Value, ref2.Value);  
32 ]]></code_example>deserve further comment, as they demonstrate some of the string formatting behavior of Console.WriteLine, which, in fact, takes a variable number of arguments. The first argument is a string, which may contain numbered placeholders like {0} and {1}. Each placeholder refers to a trailing argument with {0} referring to the second argument, {1} referring to the third argument, and so on. Before the output is sent to the console, each placeholder is replaced with the formatted value of its corresponding argument. </paragraph>
33   <paragraph>Developers can define new value types through enum and struct declarations, and can define new reference types via class, interface, and delegate declarations. The example <code_example><![CDATA[
34 using System;  
35 public enum Color  
36 {  
37    Red, Blue, Green  
38 }  
39 public struct Point   
40 {   
41    public int x, y;   
42 }  
43 public interface IBase  
44 {  
45    void F();  
46 }  
47 public interface IDerived: IBase  
48 {  
49    void G();  
50 }  
51 public class A  
52 {  
53    protected virtual void H() {  
54       Console.WriteLine("A.H");  
55    }  
56 }  
57 public class B: A, IDerived   
58 {  
59    public void F() {  
60       Console.WriteLine("B.F, implementation of IDerived.F");  
61    }  
62    public void G() {  
63       Console.WriteLine("B.G, implementation of IDerived.G");  
64    }  
65    override protected void H() {  
66       Console.WriteLine("B.H, override of A.H");  
67    }  
68 }  
69 public delegate void EmptyDelegate();  
70 ]]></code_example>shows an example of each kind of type declaration. Later sections describe type declarations in detail. </paragraph>
71 </clause>