摘要: DataTable dt=...........//获取从数据库中取出的数据(假设只有一条记录)//Cast<T>()用来将非泛型的序列转换为泛型的序列DataRow row=dt.Rows.Cast<DataRow>().Single();//OfType<T>():用来将序列中可以转换的转换为指定的序列如:一个object数组中有整数和字符串,现在想找出其中最大的数object[] obj = {1,23,4,5,555,"aaa","bbb" }; int max=obj.OfType<int>(). 阅读全文
posted @ 2013-06-16 21:18 程序有Bug 阅读(4391) 评论(0) 推荐(1) 编辑
摘要: 现有如下需求,要求统计int数组中每个整数的个数:int[] arrInt = {1,2,3,4,5,6,1,2,3,4,1,2,3 }; var linq = from item in arrInt group item by item into g//注意这里的into g,这里必须为g 表示范围变量IGrouping<int,int> select new {key=g.Key,value=g.Count() };//这里选择了整数的值为key,个数为值的匿名对象 阅读全文
posted @ 2013-06-16 20:58 程序有Bug 阅读(356) 评论(0) 推荐(0) 编辑
摘要: 有一个字符串数组:string[]arrStr={"123","234","345","456"};现在想得到该数组中大于200的值要实现该需求,得进行两次Convert.ToInt32()操作var arrInt = from item in strArr where Convert.ToInt32(item) > 200 select Convert.ToInt32(item);现在可以使用一个临时变量来实现,只需一次Convert.ToInt32()操作var arrInt = from it... 阅读全文
posted @ 2013-06-16 20:49 程序有Bug 阅读(690) 评论(0) 推荐(0) 编辑
摘要: 1、扩展方法:类名前面加static ,方法参数前 加this,如:对string类进行扩展public static classstring { public static string Quert(this string s) //注意这里的参数形式 { return "[" + s + "]"; } }使用的时候:"aaa".Quert();//返回"[aaa]"2、仿StringBuilder的IntBuilder,实现的功能:可以像StringBuilder一样加public class IntBuild 阅读全文
posted @ 2013-06-16 18:45 程序有Bug 阅读(187) 评论(0) 推荐(0) 编辑
摘要: private void RegCompStartRun(bool cmd) { //获取程序执行路径.. string starupPath = Application.ExecutablePath; //表示Window注册表中项级节点,读取 Windows 注册表基项HKEY_LOCAL_MACHINE RegistryKey loca = Registry.LocalMachine; RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); lblDi 阅读全文
posted @ 2013-06-16 09:55 程序有Bug 阅读(282) 评论(0) 推荐(0) 编辑