接口这样写为什么会报错呢? public interface IUIBuildingBlock
{
readonly DQDataTypes DataType();
string QuestionText();
object Answer();
} 其中DQDataTypes为自定义的数据类型:
public enum DQDataTypes
{
String,Int,Double,DateTime,Currency, Boolean
};
错误为每次编译时报错: 修饰符"readonly"对该项无效
不知道那位高人遇到过这种情况,能帮帮我么?谢谢!
下面是我调用接口的用户控件的代码:
namespace WebApplication2.userControls
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls; /// <summary>
/// DQIntegerQuestion 的摘要说明。
/// </summary>
public class DQIntegerQuestion : System.Web.UI.UserControl,IUIBuildingBlock
{
protected System.Web.UI.WebControls.TextBox dqAnswer;
protected System.Web.UI.WebControls.Label dqQuestion;
protected System.Web.UI.WebControls.CompareValidator CompareValidator1; private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dqAnswer.TextChanged += new System.EventHandler(this.dqAnswer_TextChanged);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void dqAnswer_TextChanged(object sender, System.EventArgs e)
{
}
#region IUIBuildingBlock 成员 public DQDataTypes DataType
{
// TODO: 添加 DQIntegerQuestion.DataType 实现
get
{
return DQDataTypes.String;
}
} public string QuestionText
{
// TODO: 添加 DQIntegerQuestion.QuestionText 实现
get
{
return dqQuestion.Text;
}
set
{
dqQuestion.Text = Value;
}
} public object Answer
{
// TODO: 添加 DQIntegerQuestion.Answer 实现
get
{
return dqAnswer.Text;
}
set
{
dqAnswer.Text = Value;
}
} #endregion
}
}
{
readonly DQDataTypes DataType();
string QuestionText();
object Answer();
} 其中DQDataTypes为自定义的数据类型:
public enum DQDataTypes
{
String,Int,Double,DateTime,Currency, Boolean
};
错误为每次编译时报错: 修饰符"readonly"对该项无效
不知道那位高人遇到过这种情况,能帮帮我么?谢谢!
下面是我调用接口的用户控件的代码:
namespace WebApplication2.userControls
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls; /// <summary>
/// DQIntegerQuestion 的摘要说明。
/// </summary>
public class DQIntegerQuestion : System.Web.UI.UserControl,IUIBuildingBlock
{
protected System.Web.UI.WebControls.TextBox dqAnswer;
protected System.Web.UI.WebControls.Label dqQuestion;
protected System.Web.UI.WebControls.CompareValidator CompareValidator1; private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dqAnswer.TextChanged += new System.EventHandler(this.dqAnswer_TextChanged);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void dqAnswer_TextChanged(object sender, System.EventArgs e)
{
}
#region IUIBuildingBlock 成员 public DQDataTypes DataType
{
// TODO: 添加 DQIntegerQuestion.DataType 实现
get
{
return DQDataTypes.String;
}
} public string QuestionText
{
// TODO: 添加 DQIntegerQuestion.QuestionText 实现
get
{
return dqQuestion.Text;
}
set
{
dqQuestion.Text = Value;
}
} public object Answer
{
// TODO: 添加 DQIntegerQuestion.Answer 实现
get
{
return dqAnswer.Text;
}
set
{
dqAnswer.Text = Value;
}
} #endregion
}
}
{
DQDataTypes DataType{get;};
string QuestionText{get;set;};
object Answer{get;set;};
}
public class DQIntegerQuestion : System.Web.UI.UserControl,IUIBuildingBlock
中会出错,提示为:
“WebApplication2.userControls.DQIntegerQuestion”不会实现接口成员“IUIBuildingBlock.Answer()”“WebApplication2.userControls.DQIntegerQuestion”不会实现接口成员“IUIBuildingBlock.DataType()”“WebApplication2.userControls.DQIntegerQuestion”不会实现接口成员“IUIBuildingBlock.QuestionText()”不知道为什么?
public interface IUIBuildingBlock
{
DQDataTypes DataType{get;}
string QuestionText{get;set;}
object Answer{get;set;}
}
=================================
这是什么写法,DataType在接口里定义为方法,实现又是属性???
public class DQIntegerQuestion : System.Web.UI.UserControl,IUIBuildingBlock
中会出错,提示为:
“WebApplication2.userControls.DQIntegerQuestion”不会实现接口成员“IUIBuildingBlock.Answer()”“WebApplication2.userControls.DQIntegerQuestion”不会实现接口成员“IUIBuildingBlock.DataType()”“WebApplication2.userControls.DQIntegerQuestion”不会实现接口成员“IUIBuildingBlock.QuestionText()”不知道为什么?
其实这程序我是仿照别人的代码写的,不过原作者用的是VB.net,我把相应的原代码也贴出来,希望得到高手指点:DQDataTypes.vb页面:
Public Enum DQDataTypes
[String]
[Integer]
[Double]
[Date]
[Currency]
[Boolean]
End EnumIUIBuildingBlock.vb页面:
Public Interface IUIBuildingBlock
ReadOnly Property DataType() As DQDataTypes
Property QuestionText() As String
Property Answer() As Object
End Interface
关于调用接口的页面太多了,装不下,所以就没粘了:)
能给出示例代码好么?
{
DQDataTypes DataType
{
get;
}
string QuestionText
{
get;
set;
}
object Answer
{
get;
set;
}
}
那正确的写法应该怎么写呢?能帮帮我么?谢谢先
如
get
{
return object1;
}
set
{
value=object1;
}
哦,那修饰符"readonly"不要了么?
还有c#和vb.net关于接口的写法差别那么大呀?
谢谢了,那个问题没有了但是又出新的问题:
名称“Value”在类或命名空间“WebApplication2.userControls.DQIntegerQuestion”中不存在但是,我在c#入门经典书中看到好像
public string QuestionText
{
// TODO: 添加 DQIntegerQuestion.QuestionText 实现
get
{
return dqQuestion.Text;
}
set
{
dqQuestion.Text = Value;
}
}
其中的Value不需要申明的,谢谢先
Public Property QuestionText() As String Implements IUIBuildingBlock.QuestionText
Get
Return dqQuestion.Text
End Get
Set(ByVal Value As String)
dqQuestion.Text = Value
End Set
End Property
不知道为什么换成c#后就出问题了
DQDataTypes DataType
{
get;
}
只有get,就是只读的。
太感谢了,马上给分!