public class CustomerService // 类名使用PascalCase
{
private const string ConnectionString = "YourConnectionString"; // 常量名全大写,下划线分隔
public Customer GetCustomerById(int customerId) // 方法名使用PascalCase
{
string query = "SELECT * FROM Customers WHERE CustomerId = @CustomerId";
// ... 数据库操作代码 ...
Customer customer = new Customer();
// 假设从数据库中获取了数据并填充到customer对象中
return customer;
}
private void UpdateCustomerData(Customer customerToUpdate) // 方法名使用PascalCase
{
string updateQuery = "UPDATE Customers SET Name = @Name WHERE CustomerId = @CustomerId";
// ... 数据库更新操作代码 ...
}
}
public class Customer // 类名使用PascalCase
{
public int CustomerId { get; set; } // 属性名使用PascalCase
public string Name { get; set; }
// ... 其他属性 ...
}
// 使用示例
class Program
{
static void Main(string[] args)
{
CustomerService service = new CustomerService();
Customer customer = service.GetCustomerById(1); // 变量名使用camelCase
// ... 对customer对象进行操作 ...
service.UpdateCustomerData(customer);
}
}