变量名称下划线 [英] underscores on variable names

查看:158
本文介绍了变量名称下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在查看一些C#代码,并且可以在某些类中看到

实例变量,其名称以下划线开头,例如:


private string _projectId;


是否有理由在C#中使用这样的下划线?


谢谢,

彼得

解决方案

彼得,


个人喜好,我目前使用的最多是camelCase或其他类似的b $ b风格。


Cor


" Peter Kirk" < pk@alpha-solutions.dk> écritdansle message de news:
uM ******** *****@TK2MSFTNGP12.phx.gbl ...

我正在查看一些C#代码,并且可以看到某些类中有
名称以下划线开头的实例变量,例如:

私有字符串_projectId;

是否有理由在C#中使用这样的下划线?




有些人使用它作为前缀来区分字段和属性而不用

作为下划线; Delphi程序员使用一个前缀为
''F'的字段的惯例,我也看到在C#中使用了''''m'(表示我猜的内存?)


Joanna


-

Joanna Carter

顾问软件工程师


只需谷歌C#命名约定即可或者C#编码风格指南,你会发现很多信息:-)


" Joanna Carter(TeamB)" <乔***** @ nospamforme.com> schrieb im Newsbeitrag

新闻:%2 **************** @ TK2MSFTNGP10.phx.gbl ...

"彼得柯克 < pk@alpha-solutions.dk> écritdansle message de news:
uM ******** *****@TK2MSFTNGP12.phx.gbl ...

我正在查看一些C#代码,并且可以在某些类中看到
是名称以下划线开头的实例变量,例如:

私有字符串_projectId;

是否有理由在C#中使用这样的下划线?



有些人用它作为前缀来区分一个字段和一个属性
没有
下划线; Delphi程序员使用前缀字段
和'F''的惯例,我也看到C#中使用了''''''(用于表示我猜的内存?)
< Joanna

- Joanna Carter
顾问软件工程师



Hi

I am looking at some C# code, and can see in some of the classes there are
instance variables whose names start with an underscore, for example:

private string _projectId;

Is there a reason for using underscores like this in C#?

Thanks,
Peter

解决方案

Peter,

Personal preference, the most I see used at the moment is camelCase or other
styles like that.

Cor


"Peter Kirk" <pk@alpha-solutions.dk> a écrit dans le message de news:
uM*************@TK2MSFTNGP12.phx.gbl...

I am looking at some C# code, and can see in some of the classes there are
instance variables whose names start with an underscore, for example:

private string _projectId;

Is there a reason for using underscores like this in C#?



Some folks use it as a prefix to distinguish a field from a property without
an underscore; Delphi programmers use a convention of prefixing fields with
''F'', I have also seen ''''m'' used in C# (to denote memory I guess ?)

Joanna

--
Joanna Carter
Consultant Software Engineer


Just google for "C# naming conventions" or "C# coding style guide", you''ll
find lots of infos :-)

"Joanna Carter (TeamB)" <jo*****@nospamforme.com> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP10.phx.gbl...

"Peter Kirk" <pk@alpha-solutions.dk> a écrit dans le message de news:
uM*************@TK2MSFTNGP12.phx.gbl...

I am looking at some C# code, and can see in some of the classes there
are
instance variables whose names start with an underscore, for example:

private string _projectId;

Is there a reason for using underscores like this in C#?



Some folks use it as a prefix to distinguish a field from a property
without
an underscore; Delphi programmers use a convention of prefixing fields
with
''F'', I have also seen ''''m'' used in C# (to denote memory I guess ?)

Joanna

--
Joanna Carter
Consultant Software Engineer



这篇关于变量名称下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆