[英]C# Array list with class
I have the following C# class: 我有以下C#类:
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: 和以下arraylist:
List <pageViews> pviews = new List<pageViews>();
I then make an instance of the class pageViews
and populate the fields like so: 然后,我创建一个类
pageViews
的实例,并像这样填充字段:
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: 然后,我尝试将类添加到arraylist中,如下所示:
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?)
CS1061:“ System.Collections.Generic.List”不包含“ add”的定义,并且找不到扩展方法“ add”接受类型为“ System.Collections.Generic.List”的第一个参数(您是否缺少使用指令还是程序集引用?)
From what I have read, I should be using linq, which I already am: 从我阅读的内容来看,我应该使用linq,它已经是:
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? 那么,我想念的是什么,从我能看到的所有东西中我可以得到吗?
Problem on add
. add
问题。 Use Add
instead of add
. 使用
Add
代替add
。 Try: 尝试:
pviews.Add(views);
Replace add with Add
用添加替换添加
Like:- pviews.add(views); to pviews.Add(views);
像:
pviews.add(views); to pviews.Add(views);
pviews.add(views); to pviews.Add(views);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.