如何计算列表长度 [英] How do I calculate length of list
本文介绍了如何计算列表长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试着计算一下列表的长度
它给了我一个错误
这是我的班级文件
我尝试过:
I tried to calculate length of list
It gives me an error
This is my class file
What I have tried:
Delete cfmdeletelist = new Delete();
List<Delete> DeleteList = new List<Delete>();
DeleteList = cfmdeletelist.getCurrentRow();
for(int i = 0; i < cfmdeletelist.length; i++)
Severity Code Description Project File Line Suppression State
Error CS1061 'Delete' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'Delete' could be found (are you missing a using directive or an assembly reference?) eadd - Copy (2) C:\Users\Tan\Desktop\eadd - Copy (2)\StaffHomeLoan.aspx.cs 163 Active
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Text;
/// <summary>
/// Summary description for Delete
/// </summary>
public class Delete
{
public int loanterm { get; set; }
public String Type { get; set; }
public int loanrate { get; set; }
public List<Delete> getCurrentRow()
{
List<Delete> deletelist = new List<Delete>();
// Step 4 :Retrieve connection string from web.config
string DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
// Step 5 :Create SQLcommand to select LoanTerm and LoanRate from LoanRate table where the rate is current
StringBuilder sqlStr = new StringBuilder();
sqlStr.AppendLine("SELECT LoanRate,LoanTerm,Loanloantype From LoanMaster ");
// Step 6 :Instantiate SqlConnection instance and SqlCommand instance
SqlConnection myConn = new SqlConnection(DBConnect);
SqlCommand cmd = new SqlCommand(sqlStr.ToString(), myConn);
// Step 7 :Open connection then execute reader
myConn.Open();
SqlDataReader reader = cmd.ExecuteReader();
// Step 8 : if reader has no rows return, set the typelist to null
if (!reader.HasRows)
{
deletelist = null;
}
else
while (reader.Read())
{
Delete Deleted = new Delete();
Deleted.Type = reader["Loanloantype"].ToString();
Deleted.loanterm = Convert.ToInt32(reader["LoanTerm"]);
Deleted.loanrate = Convert.ToInt32(reader["LoanRate"]);
deletelist.Add(Deleted);
List<Delete> distinct = deletelist.ToList();
}
// Step 11: Close the reader and connection
myConn.Close();
reader.Close();
return deletelist;
}
}
//
// TODO: Add constructor logic here
//
}
推荐答案
你试过吗
Have you tried
for(int i = 0; i < cfmdeletelist.Length; i++)
(资本L的长度)
您需要使用声明为List的变量 - > DeleteList
(Capital L in Length)
You need to use the variable declared as a List -> DeleteList
Delete elementToDelete;
for(int i = 0; i < DeleteList.Length; i++)
{
elementToDelete = DeleteList[i];
elementToDelete.Dispose(); // Or what ever you need to do
}
当你声明一个你自己类型的变量时这样
When you declare a variable of your own type like this
Delete cfmdeletelist = new Delete();
对象 cfmdeletelist
只包含方法您已定义的属性。
您是否为类定义了任何Length属性删除
?
the object cfmdeletelist
will only contain the methods and properties you have defined.
Did you define any Length property for the class Delete
?
这篇关于如何计算列表长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文