- Private and class-level variables should be written using camel casing
- Public members should be named using Pascal casing
- Use proper namespacing within all your .Net classes & projects such as: [CompanyName].[BusinessUnit].[ProjectName].[VSNetProjectName]
Example:
Microsoft.Office.HelloWorld.Ui
Microsoft.Office.HelloWorld.Data - Create separate projects and namespaces for your UI, Data and Business layers
- Use DataSet when retrieving results from database and the data needs to be reread, serialized, cached or multiple sets of data need to be related and joined
- Use DataReader when retrieving results from database and the data needs to be read once and displayed quickly
- Use XPathDocument when reading XML and needing to extract elements (use XPath, etc) out of the XML document
- Use XmlDocument when needing to perform two or more of the following: read, write or serialize.
- Use Command objects to execute SQL code or stored procedures
- Use EnterpriseLibrary (Application Blocks) in your application where possible, as they are a collection of best practices in working with .Net
- Use StringBuilder object to construct strings instead of using plus (+) sign to concatenate
- Use regular ‘for’ loop instead of ‘for each’ loop where possible, as traditional ‘for’ loop is faster and more efficient
- Avoid using DataAdapter objects
- Avoid using the DataGrid for inline editing, especially the more complex the process and logic is, as this creates something resembling spaghetti code
- Add attributes to web service classes and their public exposable members by using [WebService] and [WebMethod]. Properly namespace your web service and document the web service and your web methods this way
- Add XML Comments to all private and public members
- Use source code control
Technology with opinion
Wednesday, September 07, 2005
Best Practices: C# & .Net
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment