I want to put values of my camera in c# as is done in php:
$camData = array( “camera1” => array(“isEnabled” => false, “camName” => “Yard”, “defaultZoom” => 50),
“camera2” => array(“isEnabled” => true, “camName” => “Pitch”, “defaultZoom” => 35) );
In php I can retrieve data:
$isEnabled = $camData[“camera1”][“isEnabled”];
In c#, currently I want to do this:
Hashtable cameras = new Hashtable();
Hashtable camData = new Hashtable();
camData.Add(“isEnabled”,true);
camData.Add(“camName”,“Yard”);
cameras.Add(“camera1”,camData);
And retrieve it like this:
string camName = (string)cameras[“camera1”][“camName”];
But it doesnt let me do that. I have to make it really complicated:
Hashtable camera = (Hashtable)cameras[“camera1”];
string camName = (string)camera[“camName”];
Which works but is really messy. Is there a way to program this faster and more efficiently?
Lamont
2
Why not just make an object?
In your object C# file
In your other C# file:
Then to access that camera all you have to do is call “aCam”.
Lamont
3
Then you can store all your camera objects in an array (or list<>). Easier to handle.
private List sceneCams = new List();
And if, for some reason, you absolutely must have your data stored in such a fashion, use a Dictionary instead.
Dictionary<string, object> ungodlyWayToStoreObjectData = new Dictionary<string, object>();
ungodlyWayToStoreObjectData.add("isSet", true);
bool _isSet = (bool)ungodlyWayToStoreObjectData["isSet"];
And, you can then either put the Dictionaries into a list, or into another dictionary…
Note, if it wasn’t clear, I wholeheartedly recommend using a class instead as Lamont has stated.