本文介绍了C#类库中对象的类,方法,变量大小写/名称的最佳做法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是使用某些特定语言的强大开发人员,并且正在有机地学习C#,因此尝试学习什么是最佳实践.
I'm a strong developer in some niche languages, and am organically learning C#, so trying to learn what are the best practices.
例如,在构建Shopify集成时,能否获得以下示例代码块的最佳反馈?
Can I get some feedback on what's best for the following sample code block where I'm building a Shopify integration for example.
namespace WMShopify
{
// Is it common to have the namespace and class the same?
public class WMShopify
{
// Are there different practices for private/public vars?
public string APIKey { get; set; } // Capital
public string password { get; set; } // lower case
public string secretString { get; set; } // Camel
private string _combinedVar; // Camel/underscore for private
}
// Should these be in a separate *.cs file?
public class WMShopifyOrders
{
// Method capital/lower/camel?
public int getOrderCount()
{
// lower/capital/camel?
int localMemberVar = 0;
return localMemberVar;
}
}
// Should these be in a separate *.cs file?
public class WMShopifyProducts
{
public List<string> getProductList()
{
return new List<string>();
}
}
}
推荐答案
最佳实践:提出每个人都同意并遵循的标准.
Best practice: Come up with a standard that everyone agrees on and follows.
判决:书面内联
namespace WMShopify
{
// Is it common to have the namespace and class the same?
//No, namespace should probably be the name of the project itself.
public class WMShopify
//this looks like a configuration class
{
// Are there different practices for private/public vars?
public string APIKey { get; set; } // Capital
public string password { get; set; } // lower case
public string secretString { get; set; } // Camel
private string _combinedVar; // Camel/underscore for private
}
// Should these be in a separate *.cs file?
// I like to separate them because what happens when you have 100 classes, you just scroll forever?
public class WMShopifyOrders
{
// Method capital/lower/camel?
// I prefer capital
public int getOrderCount()
{
// lower/capital/camel? Sure
int localMemberVar = 0;
return localMemberVar;
}
}
// Should these be in a separate *.cs file? Yup
public class WMShopifyProducts
{
public List<string> getProductList()
{
return new List<string>();
}
}
}
这篇关于C#类库中对象的类,方法,变量大小写/名称的最佳做法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!