这是C#语句的正确语法

时间:2011-01-05 19:12:37

标签: c# asp.net

这是C语句的正确语法吗?我在尝试使用它时在Visual Studios中收到以下错误消息。

intResult = Convert.ToInt32(cmdSelect.Parameters("RETURN_VALUE").Value);
non-invocable memeber of System.Data.SqlClient.SqlCommand.Parameters can not be used as a method.

任何人都可以帮忙解决这个问题。

我也在使用以下命名空间

using System;
using System.Data;
using System.Configuration;
using System.Web.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Security;

5 个答案:

答案 0 :(得分:5)

你想使用indexer,而不是调用函数,所以你应该使用方括号:

intResult = Convert.ToInt32(cmdSelect.Parameters["RETURN_VALUE"].Value);

答案 1 :(得分:4)

应该是:

intResult = Convert.ToInt32(cmdSelect.Parameters["RETURN_VALUE"].Value);

答案 2 :(得分:4)

在C#中,索引器使用方括号,而不是VB.NET中的括号。这应该可以解决问题:

intResult = Convert.ToInt32(cmdSelect.Parameters["RETURN_VALUE"].Value);

答案 3 :(得分:3)

在参数上使用[]索引运算符而不是括号:

intResult = Convert.ToInt32(cmdSelect.Parameters["RETURN_VALUE"].Value);

答案 4 :(得分:2)

cmdSelect.Parameters["RETURN_VALUE"].Value

索引器在c#中是[],在VB.net中它们是()