#眉標=Mobile、Pex、 #副標=Windows Mobile開發系列(9) #大標=行動裝置應用程式效率最佳化 #作者=文/圖 沈炳宏 ============= 程式1 private int myVar = 1; public int MyProperty { get { return myVar; } set { myVar = value; } } private int myVVar = 1; public virtual int MyVirtualProperty { get { return myVVar; } set { myVVar = value; } } public void Test1() { … } public void Test2() { … } ================ ============= 程式2 private void demoMethodB() { int start = Environment.TickCount; Thread.Sleep(10000); int end = Environment.TickCount; int millis = end - start; MessageBox.Show(millis.ToString()); } ================ ============= 程式3 private void demoStopWatch() { Stopwatch sw = new Stopwatch(); sw.Start(); Thread.Sleep(10000); sw.Stop(); long millis = sw.ElapsedMilliseconds; MessageBox.Show(millis.ToString()); } ================ ===<反灰>============= 程式4 private void demoGlobalMemoryStatus () { MemoryStatus ms = new MemoryStatus(); GlobalMemoryStatus(ms); string result =ms… MessageBox.Show(result); } [DllImport("coredll.dll")] public static extern void GlobalMemoryStatus(MemoryStatus lpBuffer); public class MemoryStatus { public int Length; public int MemoryLoad; public int TotalPhysical; public int AvailPhysical; public int TotalPageFile; public int AvailPageFile; public int TotalVirtual; public int AvailVirtual; public MemoryStatus() { Length = Marshal.SizeOf(this); } } ================ ============= 程式5 public static void demoString() { string result = string.Empty; for (int i = 0; i < 10000; i++) { result += "demo"; } } public static void demoStringBuilder() { string result = string.Empty; StringBuilder sb = new StringBuilder(); for (int i = 0; i < 10000; i++) { sb.Append("demo ").Append("runpc"); } result = sb.ToString(); } ================