I have a bunch structure arrays like listed below that Id like to port over to C#. This is a part of a big project. How can I easily achieve something like this in C# ? Such as grouping variables ? I know a class will do but to do something like this Id perhaps ha开发者_Go百科ve to create a number of nested classes ?
robot.task.mapBuilding.exploration.isExploring = 0;
robot.task.mapBuilding.exploration.initialiseAreaExploration = 1;
robot.task.mapBuilding.exploration.isInExplorationArea = -1;
robot.task.mapBuilding.exploration.lists.canRequestNewTask = 1;
robot.task.mapBuilding.exploration.lists.requestNewTask = [];
robot.task.mapBuilding.exploration.lists.receivedNewTask = [];
Thanks in advance
I don't know anything about matlab, but based on what you have shown above you could have a class library with a robot.task.mapbuilding
namespace but it would require some classes and nested as you say.
For example an exploration
class that contains a lists
class:
namespace robot.task.mapBuilding
{
public class lists
{
public lists()
{
_canRequestNewTask= true;
}
private bool _canRequestNewTask;
private string _requestNewTask;
private string _receivedNewTask;
public bool CanRequestNewTask {get{return _canRequestNewTask;}set{_canRequestNewTask=value;}}
public string RequestNewTask{get{return _requestNewTask;}set{_requestNewTask=value;}}
public string ReceivedNewTask {get{return _receivedNewTask;}set{_receivedNewTask=value;}}
}
public class exploration
{
public exploration()
{
isExploring = false;
initialiseAreaExploration = true;
isInExplorationArea = -1;
}
private bool _isExploring;
private bool _initialiseAreaExploration;
private bool _isInExplorationArea;
private lists _lists;
public bool IsExploring {get{return _isExploring;} set{_isExploring = value;}}
public bool InitialiseAreaExploration{get{return _initialiseAreaExploration;}set{_initialiseAreaExploration=value;}}
public bool IsInExplorationArea {get{return _isInExplorationArea;}set{_isInExplorationArea=value;}}
public lists Lists {get{return _lists;}set{_lists=value;}}
}
}
edit
If you're not bothered about value validation or initialisation on construction then this could be wittled down to:
namespace robot.task.mapBuilding
{
public class lists
{
public bool CanRequestNewTask {}
public string RequestNewTask {}
public string ReceivedNewTask {}
}
public class exploration
{
public bool IsExploring {}
public bool InitialiseAreaExploration {}
public bool IsInExplorationArea {}
public lists Lists {}
}
}
Note that I've kept to the property naming convention of starting with capitals, although I haven't done so with the classes (which I suppose I should have done really).
精彩评论