惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
Recorded Future
Recorded Future
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google DeepMind News
Google DeepMind News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
M
MIT News - Artificial intelligence
云风的 BLOG
云风的 BLOG
Y
Y Combinator Blog
N
News | PayPal Newsroom
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Help Net Security
Help Net Security
博客园 - Franky
SecWiki News
SecWiki News
Recent Announcements
Recent Announcements
T
Troy Hunt's Blog
The Register - Security
The Register - Security
The Last Watchdog
The Last Watchdog
Webroot Blog
Webroot Blog
S
Security Affairs
博客园 - 司徒正美
S
Schneier on Security
I
InfoQ
博客园_首页
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Threat Research - Cisco Blogs
Forbes - Security
Forbes - Security
腾讯CDC
N
Netflix TechBlog - Medium
N
News and Events Feed by Topic
Cloudbric
Cloudbric
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
Recent Commits to openclaw:main
Recent Commits to openclaw:main
B
Blog
V
Vulnerabilities – Threatpost
C
Check Point Blog
Google DeepMind News
Google DeepMind News
Google Online Security Blog
Google Online Security Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
C
Cisco Blogs
Schneier on Security
Schneier on Security
O
OpenAI News
K
Kaspersky official blog

博客园 - 雨后出太阳

代码新建二维表 8招助你远离咽炎 C# 数据的加密解密 DbHelperSQL 判断数据库表结构公用方法 浏览器变灰的实现方式 林仕鼎:互联网正发生模式变革 SQL Server 游标使用方法 网摘:互联网的2/8原则 红杉投资过程的独特之处 [转]毕业5年,同学之间差距为何这么大 - 雨后出太阳 - 博客园 ADO.NET数据存取技术与O/R Mapping演进[转] 工作以后十不要 减少奋斗30年 怎么算是优秀的程序员--写给工作2,3年了的同行 少走弯路的十条忠告 使用 DataFormatString 属性来提供列中各项的自定义格式 .NET世界的M型化--原文作者奚江华 <转>[创业经验]程序员创业:我的软件推广成功之路 推荐奚江华著《圣殿祭祀ASP.NET 3.5 专家技术手册 C#篇-----及他的TW博客进入方法》 C#算法
一个程序员的C#命名规则<转>
雨后出太阳 · 2009-02-08 · via 博客园 - 雨后出太阳

1.用Pascal规则来命名方法和类型。
public class DataGrid
{
public void DataBind()
{

}
}

2.用Camel规则来命名局部变量和方法的参数.
public class Product
{
private string _productId;
private string _productName;

public void AddProduct(string productId,string productName)
{

}
}

3.所有的成员变量前加前缀“_”。
public class DataBase
{
private string _connectionString;
}

4.接口的名称加前缀 “I”。
public interface IConvertible
{
byte ToByte();
}

5.自定义的属性以“Attribute”结尾。
public class TableAttribute:Attribute
{

}

6.自定义的异常以Exception结尾。
public class NullEmptyException:Exception
{

}

7.方法的命名。一般将其命名为动宾短语。
public class File
{
public void CreateFile(string filePath)
{

}
public void GetPath(string path)
{

}
}

8.局部变量的名称要有意义。
不要用x,y,z等等,用For循环变量中可使用i, j, k, l, m, n。
public class User
{
public void GetUser()
{
string[] userIds={"ziv","zorywa","zlh"};

for(int i=0,k=userIds.Length;i<k;i++)
{

}
}
}

9.所有的成员变量声明在类的顶端,用一个换行把它和方法分开。
public class Product
{
private string _productId;
private string _productName;

public void AddProduct(string productId,string productName)
{

}
}

10.用有意义的名字命名namespace,如:公司名、产品名。
namespace Zivsoft//公司命名
{

}
namespace ERP//产品命名
{

}

11.建议局部变量在最接近使用它时再声明。


12.使用某个控件的值时,尽量命名局部变量。
public string GetTitle()
{
string title=lbl_Title.Text;
return title;
}

14.把引用的系统的namespace和自定义或第三方的用一个换行把它们分开。
using System;
using System.Web.UI;
using System.Windows.Forms;

using CSharpCode;
using CSharpCode.Style;

15.文件名要能反应类的内容,最好是和类同名,一个文件中一个类或一组关连类。

16.目录结构中要反应出namespace的层次。

17.大括号"{"要新起一行。
public Sample()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

我自己总结的一套命名规则,其实规则很重要,它是一种标准,可有可无,但有总会比无好,大家正在编码的同志仔细看看,给点改进意见。