用C#開發智能手機軟體:推箱子(二)

來源:互聯網
上載者:User

在上篇文章“使用 C# 開發智能手機軟體:推箱子(一)”中,我對推箱子程式作了總體介紹。這次,我先介紹 Common/Fcl.cs 來源程式檔案。

以下是引用片段:

1 using System;
2 using System.IO;
3 using System.Drawing;
4
5 namespace Skyiv.Ben.PushBox.Common
6 {
7 ///
8 /// 這裡是 .NET Framework 支援,而 .NET Compact Framework 不支援的東東
9 ///
10 static class Fcl
11 {
12 ///
13 /// 擷取為此環境定義的換行字串。-- Environment
14 ///
15 public static string NewLine { get { return "\r\n"; } }
16
17 ///
18 /// 開啟一個文字檔,將檔案的所有行讀入一個字串,然後關閉該檔案。-- File
19 ///
20 /// 要開啟以進行讀取的檔案
21 /// 包含檔案所有行的字串
22 public static string ReadAllText(string path)
23 {
24 string text = "";
25 if (File.Exists(path))
26 {
27 using (StreamReader sr = new StreamReader(path, Pub.Encode))
28 {
29 text = sr.ReadToEnd();
30 }
31 }
32 return text;
33 }
34
35 ///
36 /// 建立一個新檔案,在其中寫入指定的字串,然後關閉該檔案。-- File
37 ///
38 /// 要寫入的檔案
39 /// 要寫入檔案的字串
40 public static void WriteAllText(string path, string contents)
41 {
42 using (StreamWriter sw = new StreamWriter(path, false, Pub.Encode))
43 {
44 sw.Write(contents);
45 }
46 }
47
48 ///
49 /// 將指定的 Size 添加到指定的 Point。-- Point
50 ///
51 /// 要添加的 Point
52 /// 要添加的 Size
53 /// 加法運算的結果
54 public static Point Add(Point point, Size size)
55 {
56 return new Point(point.X + size.Width, point.Y + size.Height);
57 }
58
59 ///
60 /// 將一維數組的大小更改為指定的新大小。-- Array
61 ///
62 /// 數組元素的類型
63 /// 要調整大小的一維數組
64 /// 新數組的大小
65 public static void Resize(ref T[] array, int newSize)
66 {
67 if (array != null && array.Length == newSize) return;
68 if (array == null) array = new T[0];
69 T[] newArray = new T[newSize];
70 Array.Copy(array, newArray, Math.Min(array.Length, newArray.Length));
71 array = newArray;
72 }
73 }
74 }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.