Closed. This question is opinion-based。它当前不接受答案。
想改善这个问题吗?更新问题,以便editing this post用事实和引用来回答。
3年前关闭。
我是使用某些特定语言的强大开发人员,并且正在有机地学习C#,因此尝试学习最佳实践。
例如,在构建Shopify集成时,是否可以获取有关以下示例代码块的最佳选择的反馈?
想改善这个问题吗?更新问题,以便editing this post用事实和引用来回答。
3年前关闭。
我是使用某些特定语言的强大开发人员,并且正在有机地学习C#,因此尝试学习最佳实践。
例如,在构建Shopify集成时,是否可以获取有关以下示例代码块的最佳选择的反馈?
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>();
}
}
}
最佳答案
最佳实践:提出每个人都同意并遵循的标准。
判决:书面内联
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# - C#类库中对象的类,方法,变量用例/名称的最佳做法是什么? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35490480/