1

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 have 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

2
  • Are you looking at porting manually or writing some code to do it automatically? Commented Oct 13, 2011 at 7:38
  • manually ofcourse. this is a big project with 1000's of lines. would be nice if there was a elegant way of porting it automatically. unfortunately not. im porting so that its compatible with the microsoft robotics platform. Commented Oct 13, 2011 at 7:48

1 Answer 1

2

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).

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks chris. do you see any harm in setting the variables public without the gets and sets ??
No - if you don't wish to perform any actions on them then you could do as my added example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.