本文介绍了访问arrayList中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含ID和值的数组列表.我需要访问ArrayList中的值,以便我可以在数据库中插入任何新记录,对任何帮助都非常感谢.这是我的代码_newListOfIds是Arraylist

Hi I have an Array list with an Id and a value in it. I need to access the value in the ArrayList so that I can insert a new record in to the database any help is very much apreciated. Here''s my code The _newListOfIds is The Arraylist

if (_newListOfIds.Count > 0)
                   {
                       for (int i = 0; i < _newListOfIds.Count; i++)
                       {
                           short iNewPermissionGroupId = Convert.ToInt16(_newListOfIds[i]);
                           objPermission.PermissionGroupId = iNewPermissionGroupId;
                           objPermission.UserId = userId;
                           objPermission.Deleted = false;
                           objPermission.LastUpdateDate = dtCurrent;
                           objPermission.LastUpdateUserId = userId;
                           objPermission.CreateDate = dtCurrent;
                           objPermission.CreateUserId = userId;
                           objPermission.JoinTransaction(objTrans);
                           objPermission.Insert();
                       }
                   }

推荐答案

var value = newListOfIds[index];


无论如何,我建议使用foreach constructs遍历数组中的值,因为就运行时间而言,对索引的访问更为昂贵.


Anyway I would recommend to iterate over the values in array by using foreach constructs, as accessing over an index is more expensive in terms of running time.

foreach(var value in _newListOfIds){
/*operate with value variable*/
}


问候


这篇关于访问arrayList中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 06:42