I have the following C# class:
public class pageViews
{
public string dateTime {get; set;}
public string IPAddress {get; set;}
public string Page {get; set;}
public string Location {get; set;}
}
and the following arraylist:
List <pageViews> pviews = new List<pageViews>();
I then make an instance of the class pageViews
and populate the fields like so:
pageViews views = new pageViews();
views.dateTime = reader["DateTime"].ToString();
views.IPAddress = reader["IPAddress"].ToString();
views.Page = reader["Page"].ToString();
I then try and add the class to the arraylist like so:
pviews.add(views);
But I get the following error:
CS1061: 'System.Collections.Generic.List' does not contain a definition for 'add' and no extension method 'add' accepting a first argument of type 'System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference?)
From what I have read, I should be using linq, which I already am:
using System;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
So what am I missing, as from what I can see I have all I need?
Replace
pviews.add(views);
with
pviews.Add(views);
In C#, the List.Add
method starts with a capital A.
See the Microsoft documentation here.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments