首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >获取CS1502:<some_method>的最佳重载方法匹配包含一些无效参数

获取CS1502:<some_method>的最佳重载方法匹配包含一些无效参数
EN

Stack Overflow用户
提问于 2011-08-04 19:41:54
回答 1查看 1.8K关注 0票数 0

我目前有以下代码:

代码语言:javascript
复制
<%@ WebService Language="C#" Class="Notifications" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Script;
using System.Web.Script.Services;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

public class Notification
{
    public int id;
    public string text;

    public Notification(int m_id, string m_text)
    {
        id = m_id;
        text = m_text;
    }

    public Notification() {}
}

[System.Web.Script.Services.ScriptService]
public class Notifications : System.Web.Services.WebService {
    List<Notification> Notification = new List<Notification>();

    [WebMethod()]
    public List<Notification> GetNotifications()
    {
        var notifications = new List<Notification>();

        using (SqlConnection objSQLConnection = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connString"]))
        {
            using (SqlCommand objSQLCommand = new SqlCommand("select * from table1 where col1 = @user", objSQLConnection))
            {
                objSQLCommand.Parameters.Add("@user", SqlDbType.VarChar, 5).Value = "abc";

                objSQLConnection.Open();
                using (SqlDataReader objSQLDataReader = objSQLCommand.ExecuteReader())
                {

                    while (objSQLDataReader.Read())
                    {
                        notifications.Add(new Notification(objSQLDataReader["id"], objSQLDataReader["text"]));
                    }

                }
            }
        }

        return notifications;
    }

}

这给了我以下错误:

代码语言:javascript
复制
Compiler Error Message: CS1502: The best overloaded method match for 'Notification.Notification(int, string)' has some invalid arguments

在线上:

代码语言:javascript
复制
notifications.Add(new Notification(objSQLDataReader["id"], objSQLDataReader["text"]));

有人知道为什么会这样吗?

EN

回答 1

Stack Overflow用户

发布于 2011-08-04 20:23:49

问题是vb代码访问AppSettings (和一般的数组),如下所示:

代码语言:javascript
复制
AppSettings("keyname")

而c#处理数组的方式如下:

代码语言:javascript
复制
AppSettings["keyname"]

转换器有时很难区分数组和函数。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6940815

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档