C# 3.0 独立的<;字符串,i参数>;
我正在C# 3.0 独立的<;字符串,i参数>;,c#-3.0,C# 3.0,我正在IDictionary QueryParameters中尝试为其赋值,但失败了 示例代码: public IDictionary<string, IParameter> QueryParameters { get { return new Dictionary<string, IParameter>(); } } 公共IDictionary查询参数 { 得到 { 返回新字典(); } } 请提供一些示例或让我知道如何为iP
IDictionary QueryParameters
中尝试为其赋值,但失败了
示例代码:
public IDictionary<string, IParameter> QueryParameters
{
get
{
return new Dictionary<string, IParameter>();
}
}
公共IDictionary查询参数
{
得到
{
返回新字典();
}
}
请提供一些示例或让我知道如何为iParmeter赋值。问题是每次都返回一个新实例。尝试:
private readonly IDictionary<string, IParameter> m_QueryParameters = new Dictionary<string, IParameter>();
public IDictionary<string, IParameter> QueryParameters
{
get { return m_QueryParameters; }
}
每次调用
QueryParameters
属性时,都会返回一个新的IDictionary
实例
您可能应该将此实例保留在包含类中:
class Foo
{
private IDictionary<string, IParameter> dict =
new Dictionary<string, IParameter>();
public IDictionary<string, IParameter> QueryParameters
{
get
{
return dict;
}
}
}
我不确定您要问什么,因为您没有将IParameter指定为类型。您要做的是创建一个具有IPParameter类型的变量并将其赋值。我假设IParameter是一个接口,所以需要一个扩展IParameter并创建其实例的具体类 因此 类参数扩展了IPParameter { ... } 你的代码 i字典dict=obj。QueryParameters();//从你的方法中获取字典 参数para=新参数() 添加(“测试”,第2段)
另请参见dalle对课堂改进的回答,如图所示您是指System.Web.UI.WebControl.Parameter吗?非常感谢您的回复,但是new Parameter()是一个WebControl.Parameter,并且无法转换为Microsoft.ReportingServices.Interfaces.iParameter谢谢您的回复,但是new Parameter()是一个新的参数是一个WebControl.Parameter,无法转换为Microsoft.ReportingServices.Interfaces.IPParameter是的,我不知道您对
IPParameter
的具体类的名称。名称参数
只是一个猜测。您必须在此处使用正在实现ipParameter
的类。
class Foo
{
private IDictionary<string, IParameter> dict =
new Dictionary<string, IParameter>();
public IDictionary<string, IParameter> QueryParameters
{
get
{
return dict;
}
}
}
void SomeFunc
{
Foo f = new Foo();
f.QueryParameters.Add("name", new Parameter());
f.QueryParameters.Add("something else", new Parameter());
}