我有一堆如下所列的结构数组,我喜欢移植到C#。这是一个大项目的一部分。如何在C#中轻松实现这样的功能?如分组变量?我知道一个类会做但是要做这样的事情我或许要创建一些嵌套类?
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 = [];
提前致谢
答案 0 :(得分:2)
我对matlab一无所知,但基于你在上面展示的内容,你可以拥有一个带有robot.task.mapbuilding
命名空间的类库,但是它需要一些类并按照你的说法进行嵌套。
例如,包含exploration
类的lists
类:
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;}}
}
}
修改强>
如果您对价值验证或建筑初始化不感兴趣,那么可以将其归结为:
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 {}
}
}
请注意,我一直遵循以大写字母开头的属性命名约定,尽管我没有使用类(我想我应该这样做)。