问题描述
BusinessObjects中的代码
Code in BusinessObjects
public class Bo
{
private string _Name;
private string _Address;
private string _Phone;
public string Name
{
set { value = _Name; }
get { return _Name; }
}
public string Address
{
set { value = _Address; }
get { return _Address; }
}
public string Phone
{
set { value = _Phone; }
get { return _Phone; }
}
}
BUsiness逻辑层中的代码
Code in BUsiness Logic Layer
public class Bll
{
public void insertstudent(Bo objbo)
{
Dal objdal = new Dal();
objdal.insertstudentdetails(objbo);
}
}
DataAccessLayer中的代码
Code in DataAccessLayer
string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
public void insertstudentdetails(Bo objbo)
{
using (SqlConnection con = new SqlConnection(cs))
{
using (SqlCommand cmd = new SqlCommand("spinserttblstudent", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name",objbo.Name);
cmd.Parameters.AddWithValue("@Address",objbo.Address);
cmd.Parameters.AddWithValue("@Phone", objbo.Phone);
con.Open();
cmd.ExecuteNonQuery();
cmd.Dispose();
}
}
}
代码隐藏在文件背后
protected void btninsert_Click(object sender,EventArgs e)
{
Bo objbo = new Bo();
objbo.Name = txtname.Text;
objbo.Address = txtaddress.Text;
objbo.Phone = txtphone.Text;
Bll objbll = new Bll();
objbll.insertstudent(objbo);
}
当我构建应用程序时,我得到编译错误说明
D:\\ \\ today3-tier \ WebApplication1 \ BO\Bo.cs(10,24):警告CS0649:字段'BO.Bo._Name'永远不会分配给,并且将始终具有其默认值null
D:\today3-tier \WebApplication1 \ BO\Bo.cs(11,24):警告CS0649:从未分配字段'BO.Bo._Address',并且将始终具有其默认值null
D:\today3-tier\WebApplication1\BO\Bo.cs(12,24):警告CS0649:字段'BO.Bo._PhoneNumber '永远不会被赋予,并且总是将其默认值为null
如何摆脱它们是什么意思?
code in code behind file
protected void btninsert_Click(object sender, EventArgs e)
{
Bo objbo = new Bo();
objbo.Name = txtname.Text;
objbo.Address = txtaddress.Text;
objbo.Phone = txtphone.Text;
Bll objbll = new Bll();
objbll.insertstudent(objbo);
}
When i build the application i'am getting compilation error stating that
D:\today3-tier\WebApplication1\BO\Bo.cs(10,24): warning CS0649: Field 'BO.Bo._Name' is never assigned to, and will always have its default value null
D:\today3-tier\WebApplication1\BO\Bo.cs(11,24): warning CS0649: Field 'BO.Bo._Address' is never assigned to, and will always have its default value null
D:\today3-tier\WebApplication1\BO\Bo.cs(12,24): warning CS0649: Field 'BO.Bo._PhoneNumber' is never assigned to, and will always have its default value null
What does it mean how to get rid of them?
推荐答案
public string Name
{
set { _Name = value; }
get { return _Name; }
}
public string Address
{
set { _Address= value; }
get { return _Address; }
}
public string Phone
{
set { _Phone= value; }
get { return _Phone; }
}
check []
这篇关于'BO.Bo._Name'永远不会被赋值,并且它的默认值是null,它是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!