Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried to calculate length of list
It gives me an error
This is my class file

What I have tried:

C#
Delete cfmdeletelist = new Delete();
       List<Delete> DeleteList = new List<Delete>();
       DeleteList = cfmdeletelist.getCurrentRow();
       for(int i = 0; i < cfmdeletelist.length; i++)


C#
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



C#
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
    //
}
Posted
Updated 25-Jul-16 15:08pm

1 solution

Have you tried
C#
for(int i = 0; i < cfmdeletelist.Length; i++)

(Capital L in Length)

You need to use the variable declared as a List -> DeleteList
C#
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
C#
Delete cfmdeletelist = new Delete();

the object cfmdeletelist will only contain the methods and properties you have defined.
Did you define any Length property for the class Delete?
 
Share this answer
 
v2
Comments
Member 12652110 25-Jul-16 21:16pm    
not working
Member 12652110 25-Jul-16 21:16pm    
still same error
Member 12652110 25-Jul-16 21:18pm    
I took the list from the class file and they said the class contains no definition for 'Length'
George Jonsson 25-Jul-16 21:49pm    
See my updated answer.
Member 12652110 26-Jul-16 3:38am    
No length but i used .count and worked perfectly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900