我有一个界面,例如
public interface Details
{
int Id { get; set; }
string Name { get; set; }
}
我在另一个类中有一个方法,比如
public void GetDetails()
{
List<Details> lstDetails = new List<Details>();
DetailsImpl objDetailsImpl;
Details objDetails = new DetailsImpl();
for (int i = 1; i <= 2; i++)
{
objDetailsImpl = new DetailsImpl(); //The **DetailsImpl** class is given below
objDetails.Id = i;
if(i==1)
objDetails.Name = "FirstName";
else
objDetails.Name = "SecondName";
lstDetails.Add(objDetails);
}
objDetailsImpl.InsertRecords(lstDetails);
}
我在另一个派生类中编写InsertRecords方法,例如,
public class DetailsImpl : Details
{
Dictionary<object, object> objDictionary = new Dictionary<object, object>();
public string Name { get; set; }
public int Id { get; set; }
public int InsertRecords(List<Details> lstDetails)
{
for (int i = 0; i < lstDetails.Count; i++)
{
//i want to get the integer value "Id" from List(lstDetails)
Id = //How to get the Id value based on count, now the <lstDetails> count is 2
//i want to get the Name object value also, how to i get???
Name = Convert.ToString(String.Join(",",lstDetails.Select(s => s.Name).ToArray()));
//If i using the above line for getting **Name** value means, its comes like "FirstName,LastName", but i want **Name** value based on row.....
objDictionary.Clear();
objDictionary.Add("@Id",Id);
objDictionary.Add("@Id",Name);
//Here i passed this parameter to "ExecuteNonQry" method for insert operations
ExecuteNonQry("sp_name",objDictonary,CommandType.StoredProcedure);
}
return 1;
}
}
我想根据列表计数获取Id、Name对象值。我该如何解决这个问题?