C# 在课堂上存储价值
我有一个类和其中的一些方法,我在其中传递一些存储过程 e、 g 我想将该存储过程存储为键值对..,以便以后使用C# 在课堂上存储价值,c#,oop,C#,Oop,我有一个类和其中的一些方法,我在其中传递一些存储过程 e、 g 我想将该存储过程存储为键值对..,以便以后使用 因此,如何以及在何处存储这些值,以便我以后在编码中访问它们?创建另一个静态类StoredProcedureManageras public static class StoredProcedureManager { public static string GetEmployeeDetails = "sp_GetEmployeeDetails"; public stat
因此,如何以及在何处存储这些值,以便我以后在编码中访问它们?创建另一个静态类
StoredProcedureManager
as
public static class StoredProcedureManager
{
public static string GetEmployeeDetails = "sp_GetEmployeeDetails";
public static string UpdateEmployeeName = "sp_updateEmployeeName";
// you can statically type these names or load them from file or database
. . .
}
注意:访问说明符取决于您希望提供给StoredProcedureManager类的范围
要访问SP名称,请执行以下操作:
obj.ExecuteNonQuery(StoredProcedureManager.GetEmployeeDetails);
obj.ExecuteNonQuery(StoredProcedureManager.Procedures["GetEmployeeDetails"]);
如果必须存储在词典中
对于键值对,必须使用字典对象
public static class StoredProcedureManager
{
public static Dictionary<string, string> Procedures = new Dictionary<string, string>();
static StoredProcedureManager()
{
procedures.Add("GetEmployeeDetails", "sp_GetEmployeeDetails");
procedures.Add("UpdateEmployeeName", "sp_updateEmployeeName");
// you can statically type these names or load them from file or database
. . .
}
}
obj.ExecuteNonQuery(StoredProcedureManager.Procedures["GetEmployeeDetails"]);