C# Array list with class

user4420358

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?

Baldrick

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

C# Array or List for a single Class type

From Dev

initialize class array in initialization list c++

From Dev

Index was outside the bounds of the array when adding class to list C#

From Dev

Store data in array, object, struct, list or class. C#

From Dev

Create Class List for Each Item in Array c#

From Dev

How to create an array of list of class objects in C#

From Dev

How to sum condition in array List<class> ? Unity C#

From Dev

Sorting List of Class by indexof array

From Dev

array of std::list c

From Dev

WPF C# How to bind and set a List in custom model class in WPF with x:array

From Dev

c# calling a list of a class into another class

From Dev

Creating a List in a C# Class

From Dev

C# Copy the Class List

From Dev

Allocating an array of a class c++

From Dev

Allocating an array of a class c++

From Dev

Search array of a class c#

From Dev

C# Class (array?) issues

From Dev

Convert a list of a custom class to an object array

From Dev

multidimensional array using list class and dictionary

From Dev

Custom Array Class: Constructor for Initialization of List

From Dev

Convert JSON array to Java Class Object List

From Dev

Add an element from another class to an array list

From Dev

Insert array list in parent class to override with subclasses

From Dev

Custom Array Class: Constructor for Initialization of List

From Dev

Initializing a particular class member in an Array List

From Dev

Array of List of class Association<K,V> Generic

From Dev

VB.NET Custom class list of array

From Dev

How to convert a list of Class objects into an array?

From Dev

How to access in Array List model class

Related Related

HotTag

Archive