一个是编译时,一个是运行时,请问在ASPX页面初始化时,
申明变量public class Defalut2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox ChannelName;
protected System.Web.UI.WebControls.Button btnChannelAdd;
protected System.Web.UI.WebControls.DataGrid dg1;
private const string TableName = "Class";//这里用const好还是readonly好?petshop3.0大部分用的是const
const 字段是编译时常数,而 readonly 字段可用于运行时常数,readonly 字段可以在声明或构造函数中初始化。因此,根据所使用的构造函数,readonly 字段可能具有不同的值。另外,const 字段是编译时常数,而 readonly 字段可用于运行时常数,
申明变量public class Defalut2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox ChannelName;
protected System.Web.UI.WebControls.Button btnChannelAdd;
protected System.Web.UI.WebControls.DataGrid dg1;
private const string TableName = "Class";//这里用const好还是readonly好?petshop3.0大部分用的是const
const 字段是编译时常数,而 readonly 字段可用于运行时常数,readonly 字段可以在声明或构造函数中初始化。因此,根据所使用的构造函数,readonly 字段可能具有不同的值。另外,const 字段是编译时常数,而 readonly 字段可用于运行时常数,
类 常量用 const,对象 “常量” 用 readonly,实际上不能算“常量”,但是一个对象被实例化,其 readonly 字段即无法修改,2。
private const string TableName = "Class";//这里用const好还是readonly好?petshop3.0大部分用的是const
=======
petshop 3.0 中 SQLServerDAL 项目中的 const 是与类本身相关的,
比如,那些 SQL 语句,你并没有初始化一个 SQLServerDAL.Order 实例就修改一次 SQL_INSERT_ORDER 吧?
晕,我只在aspx页面上放一个表名啊,表名一般不变的,但是有可能会变名称,=======那你连 readonly 都用不了,因为 .aspx[.cs] 页面不是由于你实例化的很赞赏 LZ 的钻研精神,但要搞清楚问题本质