diff --git "a/c#/for\345\276\252\347\216\257\351\230\262\345\276\241\346\200\247\347\274\226\347\250\213.cs" "b/c#/for\345\276\252\347\216\257\351\230\262\345\276\241\346\200\247\347\274\226\347\250\213.cs" index 5547a952525ee72fc2ab1c03f731ab695ee47568..f5276c170a426005f669e187869c29018eb96b39 100644 --- "a/c#/for\345\276\252\347\216\257\351\230\262\345\276\241\346\200\247\347\274\226\347\250\213.cs" +++ "b/c#/for\345\276\252\347\216\257\351\230\262\345\276\241\346\200\247\347\274\226\347\250\213.cs" @@ -1,11 +1,29 @@ 代码片段 +经过一定简化 +class Obj{ + public int total{get;set;} //total就是rows的行数 + public List rows{get;set;}=new List(); +} +…… +其中某函数中: +Obj obj=new Obj(); //演示,简化过 + +//……obj初始化…… +//通过ORM从数据库中拿数据 + +int have_i=0; +int count=obj.rows.total; for (int i = 0; i < count; i++) { - if (i >= count) + if (i >= obj.rows.Length) { break; } - …… + if(obj.rows[i]!=null /*&& 其他条件*/){ + have_i++; + //……一些操作…… + } } +设置总数量的函数(have_i); -防御性编程,我直呼内行 \ No newline at end of file +//防御性编程,我直呼内行 \ No newline at end of file