标签:private add .sh foreach adk class des count new
有时候执行结果错误,可是vs没抛异常。这时能够用trycatch来帮我们捕捉异常。
比如:bug的情况是treeview仅仅显示一个根节点和一个子节点,还不报错。我擦~
private void f_script_Load(object sender, EventArgs e) { List<t_scripts> parents = new t_scriptsBLL().getByParentId(0) as List<t_scripts>; try { foreach (t_scripts p in parents) { //TreeNode tn = new TreeNode(p.name); TreeNode tn = new TreeNode(); tn.Text = p.name; treeView1.Nodes.Add(tn); addChildrenNodes(tn, (int)p.id); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
以下我找到那个非常二的bug了
//List<string> sum = new List<string>();//不报错 List<string> sum = null;//报错 foreach (string s in sum) { Console.WriteLine("??"); } Console.WriteLine("!"); Console.ReadKey();
list假设未赋值是count=0的list。而不是null。foreach不能对null遍历。
ok。睡觉
标签:private add .sh foreach adk class des count new
原文地址:http://www.cnblogs.com/jzdwajue/p/7114774.html