用C#开发智能手机软件:推箱子(二)

2007-10-16 11:58:08 来源:博客园 作者:银河 点击:
在上篇文章“使用 C# 开发智能手机软件:推箱子(一)”中,我对推箱子程序作了总体介绍。这次,我先介绍 Common/Fcl.cs 源程序文件。



  在上篇文章“使用 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 }

9 7 3 1 2 4 8 :



本类最新行业评测技巧教程学院
本类热点本日本周本月
本类推荐本日本周本月

广告联系 | 版权说明 | 意见建议 | 加入收藏 | 军网站群 [ 军软件园 - 军软件商城 - 军软件园论坛 ]

电信与信息服务业务经营许可证:京ICP证050203