2014年3月25日

C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值

摘要: 属性类 temp = new 属性类();string s = string.Empty;foreach (System.Reflection.PropertyInfo info in typeof(类名.属性类).GetProperties()) { txtResult.AppendText("【"+info.Name + "】:"+info.GetValue(temp, null) + "\r\n"); }输出结果:【itemId】:3580447722220【title】:2014四大容量大包手提单肩包女士包【pic_url】: 阅读全文

posted @ 2014-03-25 22:29 nanphon 阅读(259) 评论(0) 推荐(0) 编辑

2014年3月24日

WinForm中DataReader绑定到DataGridView的两种方法

摘要: 在WinForm中,DataReader是不能直接绑定到DataGridView的,我想到了用两种方法来实现将DataReader绑定到DataGridView。SqlCommand command = new SqlCommand(QueryString, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); //方法一,借助于DataTable //DataTable table = new DataTable(); ... 阅读全文

posted @ 2014-03-24 21:02 nanphon 阅读(647) 评论(0) 推荐(0) 编辑

2014年3月16日

c# 正则表达式regex心得

摘要: 5.1. C#中的正则表达式的简介C#中的Regex类处理正则表达式。5.2. C#正则表达式的语法5.3. C#中的正则表达式的特点下面总结一些C#中的正则表达式相对于其他语言中的正则表达式的一些特点,包括优点和缺点:可以一次性的即搜索多个匹配的整个的字符串,同时又可以一次性地,对于每个字符串,在给定Regex的时候,就分组group,然后得到macthes之后,foreach处理每个match,已经可以得到对应的匹配的结果,可以使用不同group的值了。还是很方便的。对于匹配多个字符串的时候,好像不能加括号分组的,如果加括号分组了,那么只能匹配单个一个group就结束了。对应的要匹配多个字 阅读全文

posted @ 2014-03-16 02:15 nanphon 阅读(2182) 评论(0) 推荐(0) 编辑

c# regex Match Matches MatchCollection 用法

摘要: string text = "1A 2B 3C 4D 5E 6F 7G 8H 9I 10J 11Q 12J 13K 14L 15M 16N ffee80 #800080";Regex rgx = new Regex(@"((\d+)([a-z]))\s+", RegexOptions.IgnoreCase);MatchCollection mm = rgx.Matches(text);string x=mm[5].Groups[2].Captures[0].Value; //x为第六个集合 第二组 的值 6 /// /// 显示Match内多个Group 阅读全文

posted @ 2014-03-16 01:56 nanphon 阅读(4806) 评论(0) 推荐(1) 编辑

2014年3月13日

c# winform 获取listview 选中行某列的值

摘要: 给listview填充数据: for (int i = 0; i 0判断,将导致获取listview.Items[]索引超界的异常if (listview.SelectedIndices != null && listview.SelectedIndices.Count>0){ListView.SelectedIndexCollection c = listview.SelectedIndices;lblTitle.Text = listview.Items[c[0]].Text;}} 阅读全文

posted @ 2014-03-13 04:05 nanphon 阅读(16231) 评论(1) 推荐(0) 编辑

2014年3月12日

C# 常用代码片段

摘要: 一、从控制台读取东西代码片断:using System;class TestReadConsole{ public static void Main() { Console.Write(Enter your name:); string strName = Console.ReadLine(); Console.WriteLine( Hi + strName); }}二、读文件代码片断:using System; using System.IO; public class TestReadFile { public stat... 阅读全文

posted @ 2014-03-12 11:43 nanphon 阅读(374) 评论(0) 推荐(0) 编辑

导航