Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在课堂上存储价值_C#_Oop - Fatal编程技术网

C# 在课堂上存储价值

C# 在课堂上存储价值,c#,oop,C#,Oop,我有一个类和其中的一些方法,我在其中传递一些存储过程 e、 g 我想将该存储过程存储为键值对..,以便以后使用 因此,如何以及在何处存储这些值,以便我以后在编码中访问它们?创建另一个静态类StoredProcedureManageras public static class StoredProcedureManager { public static string GetEmployeeDetails = "sp_GetEmployeeDetails"; public stat

我有一个类和其中的一些方法,我在其中传递一些存储过程

e、 g

我想将该存储过程存储为键值对..,以便以后使用


因此,如何以及在何处存储这些值,以便我以后在编码中访问它们?

创建另一个静态类
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"]);