8fac0f9d23e2ed9df27b02b5200cf713eff79844
[mono.git] / mcs / class / Mono.C5 / current / UserGuideExamples / GettingStarted.cs
1 /*\r
2  Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft\r
3  Permission is hereby granted, free of charge, to any person obtaining a copy\r
4  of this software and associated documentation files (the "Software"), to deal\r
5  in the Software without restriction, including without limitation the rights\r
6  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
7  copies of the Software, and to permit persons to whom the Software is\r
8  furnished to do so, subject to the following conditions:\r
9  \r
10  The above copyright notice and this permission notice shall be included in\r
11  all copies or substantial portions of the Software.\r
12  \r
13  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
14  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
15  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
16  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
17  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
18  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
19  SOFTWARE.\r
20 */\r
21 \r
22 // C5 example: GettingStarted 2005-01-18\r
23 \r
24 // Compile with \r
25 //   csc /r:C5.dll GettingStarted.cs \r
26 \r
27 using System;\r
28 using C5;\r
29 using SCG = System.Collections.Generic;\r
30 \r
31 namespace GettingStarted {\r
32   class GettingStarted {\r
33     public static void Main(String[] args) {\r
34       IList<String> names = new ArrayList<String>();\r
35       names.AddAll(new String[] { "Hoover", "Roosevelt", \r
36                                   "Truman", "Eisenhower", "Kennedy" });\r
37       // Print list:\r
38       Console.WriteLine(names);\r
39       // Print item 1 ("Roosevelt") in the list:\r
40       Console.WriteLine(names[1]);\r
41       // Create a list view comprising post-WW2 presidents:\r
42       IList<String> postWWII = names.View(2, 3);\r
43       // Print item 2 ("Kennedy") in the view:\r
44       Console.WriteLine(postWWII[2]);\r
45       // Enumerate and print the list view in reverse chronological order:\r
46       foreach (String name in postWWII.Backwards()) \r
47         Console.WriteLine(name);\r
48     }\r
49   }\r
50 }\r