Hey all I have a question that may or may not have the answer I am looking for.
I want to set the variable _data to something generic so that I can set it again with the proper class name in an if statement.
Example is:
- public static void whichStatus(string dataName, object data, sessionVars sVars)
- {
- if (dataName == "SAVE_PNo_tTrip")
- {
- object _data;
- var pageName = data.GetType().DeclaringType.Name;
-
- if (pageName == "CAttend")
- {
- CAttend.SAVE_PNo_tTrip _data = (CAttend.SAVE_PNo_tTrip)data;
-
- }
- etc...etc...
- }
-
- switch (sVars.userCategory.ToUpper())
- {
- case "CCLASS":
-
- break;
- case "LNC":
-
-
- break;
- etc.. etc...
- }
As you see from the above, I am trying to just set _data to something so that I actually define it in the if statement below it. I'll also need to access it from other places within that function so that's why I need to define it at the beginning. Though I am getting an error:
Error CS0136 A local or parameter named '_data' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
Is it at all possible to do this the way I am trying to do it?