java - 带有类的 C# 数组列表

标签 java c# linq

我有以下 C# 类:

public class pageViews
{
    public string dateTime {get; set;}
    public string IPAddress {get; set;}
    public string Page {get; set;}
    public string Location {get; set;}
}

和以下数组列表:

List <pageViews> pviews = new List<pageViews>();

然后我创建类 pageViews 的实例并像这样填充字段:

pageViews views = new pageViews();

views.dateTime = reader["DateTime"].ToString();
views.IPAddress = reader["IPAddress"].ToString();
views.Page = reader["Page"].ToString();

然后我尝试像这样将类添加到数组列表中:

pviews.add(views);

但是我得到以下错误:

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?)

根据我的阅读,我应该使用 linq,我已经在使用了:

using System;
using System.Web.Configuration; 
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;

那么我缺少什么,因为据我所知,我拥有我所需要的一切?

最佳答案

替换

pviews.add(views);

pviews.Add(views);

在 C# 中,List.Add 方法以大写 A 开头。

请参阅 Microsoft 文档 here .

关于java - 带有类的 C# 数组列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30544820/

相关文章:

Java 使用栈进行归并排序

java - 如何将 google OAuth 与 java servlet 集成?

java - 为什么 Collector 接口(interface)的 combiner 与重载的 collect 方法不一致?

java - 使用 SOLR 来自 Cassandra 数据库没有响应

c# - MSIL 或 native 代码中的 "Unreachable code detected"

c# - 计算文本文件中满足条件的行数

c# - <schema> 级别的 XmlSchema 读取注释

c# - 使用带有 MVC 的 C# 将 CSS 扁平化为 HTML

c# - Linq 包含困惑

c# - 当 .Count() 大于零时从 .Select() 获取 NullReferenceException LINQ to XML