C#中好像有种变量比必须一下划线开头,什么变量是这样命名的?
4个回答
展开全部
不是必须的,这样比较方便代码的编写,如下:
public class PCase
{
private int _CaseID;
private int _CaseSortID;
private string _Title;
private string _Picture;
private string _Depict;
private bool _IsVouch;
public int CaseID
{
get { return _CaseID; }
set { _CaseID = value; }
}
public int CaseSortID
{
get { return _CaseSortID; }
set { _CaseSortID = value; }
}
public string Title
{
get { return _Title; }
set { _Title = value; }
}
public string Picture
{
get { return _Picture; }
set { _Picture = value; }
}
public string Depict
{
get { return _Depict; }
set { _Depict = value; }
}
public bool IsVouch
{
get { return _IsVouch; }
set { _IsVouch = value; }
}
}
public class PCase
{
private int _CaseID;
private int _CaseSortID;
private string _Title;
private string _Picture;
private string _Depict;
private bool _IsVouch;
public int CaseID
{
get { return _CaseID; }
set { _CaseID = value; }
}
public int CaseSortID
{
get { return _CaseSortID; }
set { _CaseSortID = value; }
}
public string Title
{
get { return _Title; }
set { _Title = value; }
}
public string Picture
{
get { return _Picture; }
set { _Picture = value; }
}
public string Depict
{
get { return _Depict; }
set { _Depict = value; }
}
public bool IsVouch
{
get { return _IsVouch; }
set { _IsVouch = value; }
}
}
参考资料: 项目属性类
展开全部
按照编程中的规则是private 私有的变量需要以'_'开头
但是在实际中可以不必遵守,但是使用规范会提高代码的可读性
所以建议还是尽量符合规则
但是在实际中可以不必遵守,但是使用规范会提高代码的可读性
所以建议还是尽量符合规则
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没有必须的吧,私有变量习惯上这样,但是不必须
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不是必须的,这样比较方便代码的编写,如下:
public
class
PCase
{
private
int
_CaseID;
private
int
_CaseSortID;
private
string
_Title;
private
string
_Picture;
private
string
_Depict;
private
bool
_IsVouch;
public
int
CaseID
{
get
{
return
_CaseID;
}
set
{
_CaseID
=
value;
}
}
public
int
CaseSortID
{
get
{
return
_CaseSortID;
}
set
{
_CaseSortID
=
value;
}
}
public
string
Title
{
get
{
return
_Title;
}
set
{
_Title
=
value;
}
}
public
string
Picture
{
get
{
return
_Picture;
}
set
{
_Picture
=
value;
}
}
public
string
Depict
{
get
{
return
_Depict;
}
set
{
_Depict
=
value;
}
}
public
bool
IsVouch
{
get
{
return
_IsVouch;
}
set
{
_IsVouch
=
value;
}
}
}
public
class
PCase
{
private
int
_CaseID;
private
int
_CaseSortID;
private
string
_Title;
private
string
_Picture;
private
string
_Depict;
private
bool
_IsVouch;
public
int
CaseID
{
get
{
return
_CaseID;
}
set
{
_CaseID
=
value;
}
}
public
int
CaseSortID
{
get
{
return
_CaseSortID;
}
set
{
_CaseSortID
=
value;
}
}
public
string
Title
{
get
{
return
_Title;
}
set
{
_Title
=
value;
}
}
public
string
Picture
{
get
{
return
_Picture;
}
set
{
_Picture
=
value;
}
}
public
string
Depict
{
get
{
return
_Depict;
}
set
{
_Depict
=
value;
}
}
public
bool
IsVouch
{
get
{
return
_IsVouch;
}
set
{
_IsVouch
=
value;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询