摘要: short s=1; s=s+1; 自然是编译不通过的 提示损失精度 那么 short s=1; s+=1; 为什么能编译通过那? 还有一个问题 隐式类型转换可以从小到大自动转,即byte->short->int->long如果反过来会丢失精度,必须进行显示类型转换 s+=1的意思与s=s+1不同,s=s+1这句先执行s+1然后把结果赋给s,由于1为int类型,所以s+1的返回值是int, 编译器自动进行了隐式类型转换所以将一个int类型赋给short就会出错,而s+=1不同由于是+=操作符,在解析时候s+=1就等价于s = (short)(s+1),翻番来讲就... 阅读全文
posted @ 2011-12-01 16:05 Relict 阅读(5577) 评论(0) 推荐(1) 编辑
摘要: 题目:已知数A和数B,且A>B数列一:第一个数为1/(A+B),增量为2/(A+B),往下递增,即1/(A+B)、3/(A+B)、5/(A+B)……数列二:第一个数为1/(A-B),增量为2/(A-B),往下递增,即1/(A-B)、3/(A-B)、5/(A-B)……两个数列放到一起排序,求排序后的第n个数是多少?答案 : 没测试过 1 using System; 2 3 namespace ConsoleApplication1 4 { 5 class Program 6 { 7 static void Main(string[] args) 8 ... 阅读全文
posted @ 2011-11-17 11:08 Relict 阅读(517) 评论(0) 推荐(0) 编辑
摘要: 题目:完成如下代码,使其输出“Hello World!”1 if() printf("Hello"); else printf(" World!");我很快想到了答案。然后同学告诉我这个题不止一个答案。如果换成C#,也可以这样问:完成如下代码,使其输出“Hello World!” 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 namespace HelloWorld 6 { 7 class Program 8 阅读全文
posted @ 2011-11-17 11:01 Relict 阅读(2828) 评论(0) 推荐(0) 编辑
摘要: private void CopyDir(string srcPath, string aimPath) { try { // 检查目标目录是否以目录分割字符结束如果不是则添加 if (aimPath[aimPath.Length - 1] != System.IO.Path.DirectorySeparatorChar) { aimPath += System.IO.Path.DirectorySeparatorChar; } // 判断目标目录是否存在如果不存在则新建 if (!System.IO.Directory.Exists(aimPath)) { System.IO.Directo 阅读全文
posted @ 2011-11-16 10:11 Relict 阅读(1054) 评论(0) 推荐(0) 编辑
摘要: 1 using System; 2 using System.Text; 3 4 ///<summary> 5 ///汉字拼音声母计算类 6 ///</summary> 7 public class ChineseConvertor 8 { 9 private ChineseConvertor() { }10 11 ///<summary>12 ///获取一串汉字的拼音声母13 ///</summary>14 ///<param name="chinese">Unicode格式的汉字字符串</param> 阅读全文
posted @ 2011-11-16 09:40 Relict 阅读(321) 评论(0) 推荐(0) 编辑