?? program.cs
字號:
using System;
using System.Collections.Generic;
using System.Text;
namespace Chapter34
{
class Program
{
static void Main(string[] args)
{
//Console.Write("請輸入您的年齡: ");
//int iAge = int.Parse(Console.ReadLine());
//string s = "";
//if (iAge > 0 && iAge < 6)
// s = "嬰兒";
//else if (iAge >= 6 && iAge < 14)
// s = "少年";
//else if (iAge >= 14 && iAge < 35)
// s = "青年";
//else if (iAge >= 35 && iAge < 60)
// s = "中年";
//else if (iAge >= 60)
// s = "老年";
//else
// return;
//Console.WriteLine(string.Format("您屬于{0}", s));
//Console.WriteLine("請選擇一個操作:");
//Console.WriteLine("1.操作1");
//Console.WriteLine("2.操作2");
//Console.WriteLine("3.操作3");
//Console.Write("請輸入操作代號(1-3): ");
//int i = int.Parse(Console.ReadLine());
//switch (i)
//{
// case 1:
// Console.WriteLine("操作1開始");
// Console.WriteLine("操作1完成");
// break;
// case 2:
// Console.WriteLine("操作2開始");
// Console.WriteLine("操作2完成");
// break;
// case 3:
// Console.WriteLine("操作3開始");
// Console.WriteLine("操作3完成");
// break;
// default:
// Console.WriteLine("操作代號錯誤");
// break;
//}
//Console.WriteLine("請選擇一個操作:");
//Console.WriteLine("1.操作1");
//Console.WriteLine("2.操作2");
//Console.WriteLine("3.操作3");
//Console.Write("請輸入操作代號(1-3): ");
//int i = int.Parse(Console.ReadLine());
//if (i == 1)
//{
// Console.WriteLine("操作1開始");
// Console.WriteLine("操作1完成");
//}
//else if (i == 2)
//{
// Console.WriteLine("操作2開始");
// Console.WriteLine("操作2完成");
//}
//else if (i == 3)
//{
// Console.WriteLine("操作3開始");
// Console.WriteLine("操作3完成");
//}
//else
// Console.WriteLine("操作代號錯誤");
//int i = 1;
//while (i < 6)
//{
// Console.WriteLine(i);
// i++;
//}
//int i = 1;
//while (i++ < 6)
// Console.WriteLine(i-1);
//int iResult = 0;
//Console.Write("1+2+3+....n,n= ");
//int n = int.Parse(Console.ReadLine());
//int i = 1;
//while (i <= n)
//{
// iResult += i;
// i++;
//}
//Console.WriteLine("累加結果為 {0}", iResult);
//int i = 1;
//do
//{
// Console.WriteLine(i);
// i++;
//}
//while (i < 1);
//int i = 1;
//for (; i <= 5;)
//{
// Console.WriteLine(i);
// i += 2;
//}
//string [] StringArray = { "小朱", "小張", "小王" };
//for (int i = 0; i < StringArray.Length; i++)
// Console.WriteLine(StringArray[i]);
//string [] arr = Enum.GetNames(typeof(Direction));
//for(int i=0;i<arr.Length;i++)
// Console.WriteLine(arr[i]);
//int[] list = { 1, 0, 6, 7, 5, 9, 2, 8, 4, 3 };
//Console.Write("排序前:");
//// 遍歷數組輸出所有元素
//for (int i = 0; i < list.Length; i++)
// Console.Write(list[i]);
//Console.WriteLine();
//int tmp = 0; // 用于交換變量
//bool isOK = false; // 表示是否還需要排序
//while (!isOK)
//{
// isOK = true;
// for (int i = 0; i < list.Length - 1; i++)
// {
// // 如果下一個元素大于這個元素
// if (list[i] > list[i + 1])
// {
// // 交換兩者
// tmp = list[i];
// list[i] = list[i + 1];
// list[i + 1] = tmp;
// // 進行了一次交換表明還需要再次排序
// isOK = false;
// }
// }
//}
//Console.Write("排序后:");
//for (int i = 0; i < list.Length; i++)
// Console.Write(list[i]);
//Console.WriteLine();
//string[] StringArray = { "小朱", "小張", "小王" };
//foreach (string s in StringArray)
// Console.WriteLine(s);
//int[] list = { 1, 2, 3, 4 };
//for (int i = 0; i < list.Length; i++)
// list[i] *= 10;
//foreach (int i in list)
// Console.WriteLine(i);
//// 不使用強制類型轉換操作把字符串轉化為數字
//string s = "-0001234567890"; // 在代碼中考慮了正負數的情況
//double iResult = 0; // 存放結果
//int tmp = 1; // 輸出前把結果乘以這個數用于處理正負數的情況
//if (!char.IsNumber(s[0])) // 如果字符串第一個字符不是數字
//{
// if (s.IndexOf('-') == 0) // 如果字符串第一個字符是'-'
// {
// s = s.TrimStart('-'); // 去除第一個字符
// tmp = -1; // 結果乘以-1就得到了負數
// }
// else if (s.IndexOf('+') == 0) // 如果字符串第一個字符是'+'
// s = s.TrimStart('+'); // 去除第一個字符
// else // 如果字符串第一個字符是其它字符
// return; // 直接返回
//}
//for (int i = 0; i < s.Length; i++)
//{
// char c = s[i]; // 得到當前字符
// int iCurrentNum = c - '0'; // 把字符轉化為整數
// iResult += iCurrentNum * Math.Pow(10, s.Length - i - 1); // 結果加上當前數字*10的N次方
// // 其實原理就是 123=1*10的2次方+2*10的一次方+3*10的0次方
//}
//iResult *= tmp;
//Console.WriteLine(iResult);
////不使用強制類型轉換操作把數字轉化為字符串
//int iNum = -123456; // 在代碼中考慮了正負數的情況
//bool b = iNum < 0; // 是否是負數
//iNum *= b ? -1 : 1; // 是負數則轉換為正書
//string sResult = ""; // 存放結果
//while (iNum % 10 != 0) // 從最后一位開始逐一獲得數字
//{
// int iCurrentNum = iNum % 10; // 取得當前數字,比如第一次循環iCurrentNum=6,第二次循環iCurrentNum=5
// sResult += iCurrentNum; // 把數字加入字符串,比如第一次循環sResult=6,第二次循環sResult=65
// iNum -= iCurrentNum; // 減去當前數字,比如第一次循環iNum=123450,第二次循環iNum=12340
// iNum /= 10; // 除以10,比如第一次循環iNum=12345,第二次循環iNum=1234
//}
////把字符串反轉
//char[] arr = sResult.ToCharArray(); // 把字符串打散為字符數組
//sResult = ""; // 清空字符串
//for (int i = arr.Length - 1; i >= 0; i--) // 從最后一位開始逐一加入字符
// sResult += arr[i];
//Console.WriteLine(b ? "-" + sResult : sResult);
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10000; i++)
sb.Append(i);
Console.WriteLine(sw.ElapsedMilliseconds);
sw.Reset();
sw.Start();
string s = "";
for (int i = 0; i < 10000; i++)
s += i;
Console.WriteLine(sw.ElapsedMilliseconds);
}
//enum Direction
//{
// North,
// South,
// East,
// West
//}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -