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);
}
}