1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.IO;
6
7 namespace CA1
8 {
9 class Program
10 {
11 static void Main(string[] args)
12 {
13 ////eg.1 输入输出
14 //int a, b;
15 //a = Convert.ToInt32(Console.ReadLine());
16 //b = Int32.Parse(Console.ReadLine());
17 //Console.WriteLine(a+b);
18
19 ////eg.2 转义字符 双引号则不能用@转义,@还可以表示多行字符串
20 //Console.WriteLine("c:\\a.text");
21 //Console.WriteLine(@"c:\a.text");
22 //Console.WriteLine("\"a.text\"");
23 //Console.WriteLine(@"abcdefg……
24 // uvwxyz");
25
26 ////eg.3 用户输入a\nb @"c:\a.text"时,还是输出a\nb @"c:\a.text"
27 ////转义符只针对在代码中直接写出的字符串,对于程序中读取出来的没有这个问题
28 //string str = Console.ReadLine();
29 //Console.WriteLine(str);
30
31 ////eg.4交换两个值,不借助其他变量
32 //int i, j;
33 //i = Convert.ToInt32(Console.ReadLine());
34 //j = Convert.ToInt32(Console.ReadLine());
35 //Console.WriteLine("交换前:i={0},j={1}", i, j);
36 //i = i + j;
37 //j = i - j;
38 //i = i - j;
39 //Console.WriteLine("交换后:i={0},j={1}", i, j);
40
41 ////eg.5 switch不要忘了break。C# 中的break不写是不行的,除了合并 case 的情况
42 ////真确例子
43 //string str = Console.ReadLine();
44 //switch (str)
45 //{
46 // case "1": Console.WriteLine("hello 1"); break;
47 // case "2":
48 // case "3": Console.WriteLine("hello 3"); break;
49 // default: Console.WriteLine("hello default");
50 // break;
51 //}
52 ////错误例子
53 //string str = Console.ReadLine();
54 //switch (str)
55 //{
56 // case "1": Console.WriteLine("hello 1"); break;
57 // case "2": Console.WriteLine("hello 2");
58 // case "3": Console.WriteLine("hello 3"); break;
59 // default: Console.WriteLine("hello default");
60 // break;
61 //}
62
63 ////eg.6 C#中bool不能用是否为0来表示true or false 错误例子:
64 //while (1)
65 //{
66 // Console.WriteLine("true");
67 //}
68
69 ////eg.7 枚举类新
70
71
72
73 ////eg.8 数组倒回来排序,foreach只能对集合进行读,不能写
74 //int[] arg = new Int32[] { 1, 3, 54, 6, 7 };
75 //Console.WriteLine("未反转之前");
76 //foreach (int i in arg)
77 //{
78 // Console.Write("{0} ", i);
79 //}
80 //Console.WriteLine();
81 //for (int i = 0; i < arg.Length/2; i++)
82 //{
83 // int temp;
84 // temp = arg[i];
85 // arg[i] = arg[arg.Length - i - 1];
86 // arg[arg.Length - i - 1] = temp;
87 //}
88 //Console.WriteLine("反转之后");
89 //foreach (int i in arg)
90 //{
91 // Console.Write("{0} ", i);
92 //}
93
94 ////eg.9 split函数
95 //string date = "2011-12-1";
96 //string[] arr = date.Split('-');
97 //date = arr[0] + "年" + arr[1] + "月" + arr[2] + "日";
98 //Console.WriteLine(date);
99
100 ////eg.9 读取文件中的值
101 //string[] lines = File.ReadAllLines(@"H:\Web开发\test\test.txt", Encoding.Default);
102 //for (int i = 0; i < lines.Length; i++)
103 //{
104 // string[] line = lines[i].Split('|');
105 // foreach (string s in line)
106 // {
107 // Console.Write(s+" ");
108 // }
109 // Console.WriteLine();
110 //}
111
112 ////eg.10 String字符串函数
113 ////字符串替换: string Replace(string oldValue, string newValue )
114 ////将字符串中的出现 oldValue 的地方替换为 newValue 。 例子:名
115 ////字替换。
116 ////取子字符串: string Substring(int startIndex) ,取从位置
117 ////startIndex 开始一直到最后的子字符串;
118 ////string Substring(int startIndex, int length) ,取从位置 startIndex
119 ////开始长度为 length 的子字符串,如果子字符串的长度不足 length
120 ////则 报错。
121 ////bool Contains(string value) 判断字符串中是否含有子串 value
122 ////bool StartsWith(string value) 判断字符串是否以子串 value 开始;
123 ////bool EndsWith (string value) 判断字符串是否以子串 value 结束;
124 ////int IndexOf(string value) : 取子串 value 第一次出现的位置。
125
126 //string str = "abcdefghijklmnopqrst";
127 //Console.WriteLine(str);
128 //bool b = str.Contains("defsa");
129 //Console.WriteLine(b);
130
131 //Console.ReadKey();
132
133
134 ////eg.11 ref out参数区别,二者都可以将值传回,ref使用前必须初始化,而out则不用
135
136 }
137 }
138 }