Author Topic: Programming Advice  (Read 10255 times)

0 Members and 1 Guest are viewing this topic.

Offline Steve Walmsley (OP)

  • Aurora Designer
  • Star Marshal
  • S
  • Posts: 11658
  • Thanked: 20379 times
Programming Advice
« on: October 11, 2010, 10:35:45 PM »
On VB2010, Joel On Software (a collection of blogs from a very insightful guy) characterizes the various .NET languages as being different syntactic sugar (my name) on top of the same underlying language.  This is accurate - what they've done is added language extensions to the various languages to essentially let you write C# (which is a truly excellent language) in those languages.  If you go to a .NET language, you might be better off simply biting the bullet and learning C# - after all, didn't SA start out as your toy to learn VB? :-)
I took your advice and looked at Visual C#. I think that is definitely the way to go so I have been following the Microsoft tutorials and written my first few test programs. The OO side is very familiar in terms of concepts, although its been a while :). Some very useful features on the UI as well, especially the TableLayoutPanel. I don't think resolution will be an issue for my next project as its very easy to write windows that scale with size.

I could use some advice though on one particular decision. I am creating a new program for me to play with Newtonian combat models and I need to create a collection class to hold ships. In C++ I created my own container classes and in VB6 there is simply one Collection object. However, in C# there is a whole array (pardon the pun!) of different Collection objects from which to derive my Ship collection, and other similar collections I will need in the future. I am guessing that I should use the Dictionary class but this is a fundamental design question so I need to get it right. Any suggestions?

Steve
 

Offline Steve Walmsley (OP)

  • Aurora Designer
  • Star Marshal
  • S
  • Posts: 11658
  • Thanked: 20379 times
Re: Programming Advice
« Reply #1 on: October 12, 2010, 05:54:38 AM »
Some more info on what I am trying to achieve. Bear in mind my OO knowledge is more than 10 years out of date so I may be using obsolete terms. I have an abstract base class called MapObject that I intend to use as the basis for a hierarchy of different objects that will appear on the eventual map for this game, including stars, planets, ships, missiles, etc.. Ship would be a derived class, or perhaps PoweredObject would be derived directly from MapObject and Ship would be derived from PoweredObject, along with Missile. Anyway, in C++ terms what I need to do is create a container class with an array of base class pointers so I can point them to derived objects of MapObject without knowing at design time what those objects will be (Late Binding I think it used to be called).

In VB6 there is a collection object which is based on arrays of a specific class, but VB6 doesn't support inheritance so there is no issue with derived classes although it obviously lacks flexibility.

In C# terms, I think I need a Dictionary collection to serve as my container class, which can apparently accept paired keys and values at design time. As I understand it, with my two days of experience :), the values can be simple data types or user-defined objects while the keys can be numeric or string-based. The Dictionary object apparently has strong type safety (where is the fun in that!) so does that mean I can only add one type of object, or can I specify MapObject as the value and then add any derived class? Also, to add my own functions at the container class level, do I actually need to create my own derived class based on Dictionary with additional, or overloaded, functions.

My intention is to have the tracking of an object's location, its speed and course, etc. and the various trigonometry functions in MapObject and then add functionality and additional data as appropriate to derived classes. For example, PoweredObject would have the thrust and fuel data and the functions for modifying course and speed based on applied thrust and changes in mass. Missile would have warhead information, tracking functions, etc. Ship would obviously have much more information and a lot of new functions. This will only work however if I can run through a for each loop and move everything at once on the Map as time progresses, which is why I need to figure out if Dictionary supports late binding or I need a different collection class, or I need to create my own collection class.

Any help appreciated. I will continue to try and work this out by myself as well :)

Steve
 

Offline Steve Walmsley (OP)

  • Aurora Designer
  • Star Marshal
  • S
  • Posts: 11658
  • Thanked: 20379 times
Re: Programming Advice
« Reply #2 on: October 12, 2010, 07:20:22 AM »
This is quickly becoming a thread where I talk to myself but I think a light bulb just went on. I guess the Dictionary class in C# would actually be equal to the array of pointers in C++, not the container class that holds them. What I assume I need to do is create a container class of my own that includes a dictionary class within it. The dictionary class is used to store the objects and the container class will add/remove/modify those objects in response to requests from the outside world.

Which just leaves the question of whether the Dictionary class can handle late-binding :)

Steve
 

Offline Beersatron

  • Gold Supporter
  • Rear Admiral
  • *****
  • Posts: 996
  • Thanked: 7 times
  • Gold Supporter Gold Supporter : Support the forums with a Gold subscription
Re: Programming Advice
« Reply #3 on: October 12, 2010, 08:08:22 AM »
Steve, I have never done C# so can't help you there but do you mind sharing your development setup? I might have a bash at something, I need to diversify a bit and so far it is just Coldfusion by Adobe that I do with a setup on my laptop to play around with AIR - also by Adobe.
 

Offline ndkid

  • Warrant Officer, Class 1
  • *****
  • n
  • Posts: 86
  • Thanked: 4 times
Re: Programming Advice
« Reply #4 on: October 12, 2010, 10:21:45 AM »
In C# terms, I think I need a Dictionary collection to serve as my container class, which can apparently accept paired keys and values at design time.

The dictionary collection is somewhat more powerful than you give it credit for with respect to the key. It is not limited to numeric or string types... you can pretty much make any sort of object your key, and can override how keys are compared to each other to determine equality.

Whether a dictionary is the best choice for your work is mostly a matter of a few factors: access, addition, and deletion. If you plan to add and remove Map Objects arbitrarily, and also want to be able to access any given map object quickly, then a Dictionary is probably a good call. If you're willing to place a cap on the number of map objects in existence, and can index with just an int, then a plain old array gives you even faster performance than a dictionary. There's probably no reason to use a list in this case, since there's no linear relationship among map objects.

The Dictionary object apparently has strong type safety (where is the fun in that!) so does that mean I can only add one type of object, or can I specify MapObject as the value and then add any derived class? Also, to add my own functions at the container class level, do I actually need to create my own derived class based on Dictionary with additional, or overloaded, functions.

It does mean that you can only add one type of object, but that's not really meaningful in more fully OO languages like C#, because everything is an object and, therefore, you can ultimately make a collection of type object and stick whatever you want into it. In fact, because C# has reflection, you could write some really godawful code like:

foreach(object foo in objects)
{
   if(foo.GetType() == typeof(int))
   {
       return 1;
   }
   else if(foo.GetType() == typeof(bar))
   {
      bar bar1 = foo;
      bar1.someFunction();
   }
}


This would be the sort of code, mind you, that would make your average OO programmer rather distressed! :-) Instead, a more OO solution would be pretty much what you propose: having a base object that things inherit from and using polymorphism. The trick is ensuring that you design your objects in a way that most things meant to deal with MapObjects don't have a reason to try and get to any subclass-specific methods or properties. So, for example, your MapObjectCollection should not itself care what sort of map object it has in its internal collection (whether it turns out to be a dictionary or something else); it should just hand out MapObject objects and, if it interacts with them, only does so as MapObjects; it shouldn't take one, figure out whether it's a missile, and then run missile-specific code for it.

If you ever want more rapid responses to C# questions, you can PM me, and I'll send along my email address so you can contact me directly. Sadly, I can't point you at any guys local to you, as my company's closest office is Belfast. :-)
 

Offline ndkid

  • Warrant Officer, Class 1
  • *****
  • n
  • Posts: 86
  • Thanked: 4 times
Re: Programming Advice
« Reply #5 on: October 12, 2010, 10:32:06 AM »
This is quickly becoming a thread where I talk to myself but I think a light bulb just went on. I guess the Dictionary class in C# would actually be equal to the array of pointers in C++, not the container class that holds them.

In C#, all objects are accessed by reference. So, in essence, whenever you declare
Foo foo;
you've only made a pointer, which is why objects in C# generally need to be constructed:
Foo foo = new Foo();

So, a dictionary certainly contains what in C++ would be called pointers, but it's most definitely not an array... C# still has array notation. So an array of pointers in C# could be:
Foo[] foo = new Foo[20];

Dictionaries are slightly more complicated, because they're based on hash tables. If you're interested in data structure design, I can go into deeper detail, but, basically, the John Q. Average Dictionary design is usually based on an expanding array that is at least twice as big as the expected size of the Dictionary. The main reason Dictionaries exist is when people want the rapid access that arrays have (and lists don't) but want more dynamic addition/deletion than arrays provide.

What I assume I need to do is create a container class of my own that includes a dictionary class within it. The dictionary class is used to store the objects and the container class will add/remove/modify those objects in response to requests from the outside world.

Whether or not you need to wrap the dictionary within another class depends on how you want the collection of objects to be accessed. If the wrapping class just exposes the ability to access and modify members of the collection, you haven't really added much. In essence, the only reason I can think of off the top of my head to wrap the MapObject collection is if you don't want anything outside it to directly use MapObject.
 

Offline Steve Walmsley (OP)

  • Aurora Designer
  • Star Marshal
  • S
  • Posts: 11658
  • Thanked: 20379 times
Re: Programming Advice
« Reply #6 on: October 12, 2010, 05:12:31 PM »
Steve, I have never done C# so can't help you there but do you mind sharing your development setup? I might have a bash at something, I need to diversify a bit and so far it is just Coldfusion by Adobe that I do with a setup on my laptop to play around with AIR - also by Adobe.

Not sure what you mean by my development setup. I am just playing with Visual C# 2010 at the moment. I have done the simple Microsoft tutorials and I am reading through various sections on the MSDN as I try out different things. It is a hit and miss approach but I like to tinker :). I have also ordered a book called Microsoft Visual C# 2010 Step by Step by John Sharp as it had good reviews on Amazon. I am going to use Access initially, although after advice from ndkid I am going to try and make sure my data access is DB independent so I could swap to SQL Server at some point.

Steve
 

Offline Steve Walmsley (OP)

  • Aurora Designer
  • Star Marshal
  • S
  • Posts: 11658
  • Thanked: 20379 times
Re: Programming Advice
« Reply #7 on: October 12, 2010, 05:26:47 PM »
The dictionary collection is somewhat more powerful than you give it credit for with respect to the key. It is not limited to numeric or string types... you can pretty much make any sort of object your key, and can override how keys are compared to each other to determine equality.

Whether a dictionary is the best choice for your work is mostly a matter of a few factors: access, addition, and deletion. If you plan to add and remove Map Objects arbitrarily, and also want to be able to access any given map object quickly, then a Dictionary is probably a good call. If you're willing to place a cap on the number of map objects in existence, and can index with just an int, then a plain old array gives you even faster performance than a dictionary. There's probably no reason to use a list in this case, since there's no linear relationship among map objects.

It does mean that you can only add one type of object, but that's not really meaningful in more fully OO languages like C#, because everything is an object and, therefore, you can ultimately make a collection of type object and stick whatever you want into it. In fact, because C# has reflection, you could write some really godawful code like:

foreach(object foo in objects)
{
   if(foo.GetType() == typeof(int))
   {
       return 1;
   }
   else if(foo.GetType() == typeof(bar))
   {
      bar bar1 = foo;
      bar1.someFunction();
   }
}


This would be the sort of code, mind you, that would make your average OO programmer rather distressed! :-) Instead, a more OO solution would be pretty much what you propose: having a base object that things inherit from and using polymorphism. The trick is ensuring that you design your objects in a way that most things meant to deal with MapObjects don't have a reason to try and get to any subclass-specific methods or properties. So, for example, your MapObjectCollection should not itself care what sort of map object it has in its internal collection (whether it turns out to be a dictionary or something else); it should just hand out MapObject objects and, if it interacts with them, only does so as MapObjects; it shouldn't take one, figure out whether it's a missile, and then run missile-specific code for it.

If you ever want more rapid responses to C# questions, you can PM me, and I'll send along my email address so you can contact me directly. Sadly, I can't point you at any guys local to you, as my company's closest office is Belfast. :-)
Thanks for the response and the offer!

My hope was that I could setup Dictionary to add MapObjects, fill it with derived objects and then override various base class functions to ensure that the container class would call functions appropriate to the complexity of the derived object. For example, if I create an UpdateCourseSpeed function, which will handle changes to course and speed based on changes in thrust, facing and external forces such a gravity, that would require code for missiles, more complex code for ships and different code for something like an asteroid, which would perhaps be a SystemBody object, derived from MapObject. The base UpdateCourseSpeed function would be in MapObject. Missile, Ship and SystemBody would have their own version of the same function. I would like to be able to run a single for each loop for every MapObject and have the code take the appropriate action for each object, although using the overriden function rather than checking the type of each object first. This is straighforward in C++. Is that what you mean above for C#, or will I need a separate Dictionary class to hold collections of Missile, Ship and SystemBody objects? Or am I just way out of date in terms of thinking and there is a better way to handle this?

Steve
 

Offline Steve Walmsley (OP)

  • Aurora Designer
  • Star Marshal
  • S
  • Posts: 11658
  • Thanked: 20379 times
Re: Programming Advice
« Reply #8 on: October 12, 2010, 05:31:56 PM »
Whether or not you need to wrap the dictionary within another class depends on how you want the collection of objects to be accessed. If the wrapping class just exposes the ability to access and modify members of the collection, you haven't really added much. In essence, the only reason I can think of off the top of my head to wrap the MapObject collection is if you don't want anything outside it to directly use MapObject.

I want to be able to run through the objects and perform various functions on them, or select a particular object by key and modify it. Can I add my own functions to the Dictionary class, such as the UpdateCourseSpeed I mentioned in my previous answer? I suppose what I am asking is should I use inherit my own version of Diictionary class with additional functions to manipulate the MapObjects, or should I just use Dictionary to hold the objects and wrap a class around that Dictionary with the functions I need? Or I am totally misunderstanding the Dictionary class?

Steve
 

Offline Beersatron

  • Gold Supporter
  • Rear Admiral
  • *****
  • Posts: 996
  • Thanked: 7 times
  • Gold Supporter Gold Supporter : Support the forums with a Gold subscription
Re: Programming Advice
« Reply #9 on: October 12, 2010, 08:47:35 PM »
Not sure what you mean by my development setup. I am just playing with Visual C# 2010 at the moment. I have done the simple Microsoft tutorials and I am reading through various sections on the MSDN as I try out different things. It is a hit and miss approach but I like to tinker :). I have also ordered a book called Microsoft Visual C# 2010 Step by Step by John Sharp as it had good reviews on Amazon. I am going to use Access initially, although after advice from ndkid I am going to try and make sure my data access is DB independent so I could swap to SQL Server at some point.

Steve

What editor do you use, does it debug and compile and step-through etc? Is there anything else you need installed other than an editor and the .net framework? Guess I am just used to developing web applications which require 3 or 4 different pieces of software just to get your server up and running correctly!
 

Offline Erik L

  • Administrator
  • Admiral of the Fleet
  • *****
  • Posts: 5656
  • Thanked: 366 times
  • Forum Admin
  • Discord Username: icehawke
  • 2020 Supporter 2020 Supporter : Donate for 2020
    2022 Supporter 2022 Supporter : Donate for 2022
    Gold Supporter Gold Supporter : Support the forums with a Gold subscription
    2021 Supporter 2021 Supporter : Donate for 2021
Re: Programming Advice
« Reply #10 on: October 12, 2010, 09:59:34 PM »
What editor do you use, does it debug and compile and step-through etc? Is there anything else you need installed other than an editor and the .net framework? Guess I am just used to developing web applications which require 3 or 4 different pieces of software just to get your server up and running correctly!
Visual Studio (VS) has the editor, compiler, step-over/into, etc all in it.

You'll need the .NET framework, and I'd suggest the various SDKs just because you never know what you might need. For databases, Access or SQLExpress are needed also.
 

Offline sloanjh

  • Global Moderator
  • Admiral of the Fleet
  • *****
  • Posts: 2805
  • Thanked: 112 times
  • 2020 Supporter 2020 Supporter : Donate for 2020
    2021 Supporter 2021 Supporter : Donate for 2021
Re: Programming Advice
« Reply #11 on: October 12, 2010, 10:42:20 PM »
Visual Studio (VS) has the editor, compiler, step-over/into, etc all in it.

You'll need the .NET framework, and I'd suggest the various SDKs just because you never know what you might need. For databases, Access or SQLExpress are needed also.
In particular, you want VS (probably 2010) Express - the free version.

John
 

Offline Steve Walmsley (OP)

  • Aurora Designer
  • Star Marshal
  • S
  • Posts: 11658
  • Thanked: 20379 times
Re: Programming Advice
« Reply #12 on: October 13, 2010, 12:01:18 AM »
OK I have hit my first serious hitch and I don't have a clue what the problem is :)

This is a function which I am going to use to load Ship objects into a collection. At the moment, the assignment to a collection isn't in the code but it will be within the forearch loop. The problem is that the code never reaches the foreach loop. I have no runtime errors and no compilation errors. I do have breakpoints on the statement above the foreach loop and on the foreach loop itself. The breakpoint is triggered for the statement above but the foreach breakpoint is never triggered. For some reason the code doesn't get there, although the form that is calling this function loads without any problem. Any suggestions?

    // container class for MapObjects
    public class MapObjectContainer
    {

        // create an instance of the Dictionary class to hold all the MapObjects
        Dictionary<int, MapObject> mCol = new Dictionary<int, MapObject>();
       
        // default constructor
        public MapObjectContainer()
        {
        }
       
         // function to load ships from database
        public void LoadDBShips()
        {

            // create an instance of the table adaptor for the Ship table
            DamoclesDataSetTableAdapters.ShipTableAdapter ShipTable = new DamoclesDataSetTableAdapters.ShipTableAdapter();

            // this code creates a new data table by calling the get data function of the table adaptor, with a parameter for GameID
            DamoclesDataSet.ShipDataTable ShipData = ShipTable.GetDataByGame(1);

            // cycle through rows in data table and use them to create objects
            foreach (DamoclesDataSet.ShipRow ShipRow in ShipData)
            {
                Ship objShip = new Ship();
                objShip.ShipID = ShipRow.ShipID;
                objShip.ShipName = ShipRow.ShipName;
                objShip.PoliticalID = ShipRow.PoliticalID;
                objShip.ShipClassID = ShipRow.ShipClassID;
                objShip.Mass = ShipRow.Mass;
                objShip.Xcor = ShipRow.XCor;
                objShip.SystemID = ShipRow.SystemID;
                objShip.Ycor = ShipRow.YCor;
               
            }
        }
    }

Steve
 

Offline sloanjh

  • Global Moderator
  • Admiral of the Fleet
  • *****
  • Posts: 2805
  • Thanked: 112 times
  • 2020 Supporter 2020 Supporter : Donate for 2020
    2021 Supporter 2021 Supporter : Donate for 2021
Re: Programming Advice
« Reply #13 on: October 13, 2010, 12:17:39 AM »

This is quickly becoming a thread where I talk to myself but I think a light bulb just went on. I guess the Dictionary class in C# would actually be equal to the array of pointers in C++, not the container class that holds them. What I assume I need to do is create a container class of my own that includes a dictionary class within it. The dictionary class is used to store the objects and the container class will add/remove/modify those objects in response to requests from the outside world.

Which just leaves the question of whether the Dictionary class can handle late-binding :)

Steve

I'm going to selectively answer tidbits from the various posts.  I'm hitting this one first, since I think it's got a lot of the most important kernels.

1)  You're right, in that Dictionary (and other containers) should be used as concrete classes that you include in other objects, rather than as base classes from which you derive.

2)  If you want something that's close to an array of objects, then List<T> is the container you want.  This is a simple container that can be iterated through using a foreach block, and allows multiple inclusions of the same object.  Dictionary<TKey, TValue> is what I usually hear referred to as an "associative array" - it allows keyed access.  Note that (IIRC) a Dictionary is implemented as something close to a hash table, in other words you can find an element in it without doing an O(N) search.  Also note that the key values in a dictionary need to be unique.

3)  It is important in C# to distinguish between Interfaces and Abstract Base Classes.  Generally speaking, you want to do polymorphism (the moral equivalent of virtual methods) by implementing interfaces, not by deriving from an abstract base class.  So for your MapObject example, you would want to define an interface IMapObject, which Ship, or Planet or Missile classes all implement.  In other words, interface inheritance (defining a set of methods whose implementations are bound at run-time based on the concrete type of the particular instance) is supported most naturally in the language by implementing interfaces, NOT by deriving from Abstract base classes.  Abstract base classes, on the other hand, are most useful to provide default implementations for the methods in the interface, i.e. it is most usefull for performing implementation inheritance (where different derived classes reuse common base class code), while still maintaining polymorphism for unshared functionality through virtual methods.

In C++ language, you won't go far wrong if you think of an Interface as being the same as a C++ Abstract Base Class with no data members and only pure virtual methods.  This also makes sense in terms of multiple inheritance - a C# class can only derive from a single class, but it can inherit from as many Interfaces as you want.  In C++, multiple inheritance doesn't stress the compiler if the "extra" base classes are all have no data or non-pure-virtuals.

Another good principle in all languages is "virtual methods should never be public".  The reason for this is that a virtual method is an interface for people who are going to derive from (specialize) the class, while public methods are an interface for people who are going to use the class (by calling its methods).  A public virtual method is trying to take on both responsibilities simultaneously - usually a bad idea :-)  Generally speaking, a virtual method should be protected (in C# - in C++ it can actually be made private), with a corresponding public non-virtual method that calls it, e.g.
Code: [Select]
public int Foo() {return FooImpl();}

protected virtual int FooImpl();

Putting all this together a nice pattern comes out:  For every interface e.g. IMapObject, define a corresponding "abstract" base class (which doesn't actually have to have any abstract or virtual methods) which implements the interfaces methods and which concrete classes can (but are not forced to) use as a base class.  For example:

Code: [Select]
    public class Point3D
    {
        // actually this is a class in System.Windows.Media.Media3D
    }
    public interface IMapObject
    {
        Point3D Location { get; set; }
    }
    public class AMapObject : IMapObject
    {
        #region private data
        Point3D _location;
        #endregion

        public Point3D Location
        {
            get
            {
                return _location;
            }
            set
            {
                _location = value;
            }
        }
    }

    public class Planet : AMapObject
    {
        #region private data
        double _radius;
        #endregion

        public double Radius
        {
            get { return _radius; }
            set { _radius = value; }
        }
    }

    public interface IWeaponsPlatform
    {
        void Shoot();
    }
    public abstract class AWeaponsPlatform : IWeaponsPlatform
    {
        #region virtual implementations of public methods
        protected abstract void ShootImpl();
        #endregion

        public void Shoot()
        {
            ShootImpl();
        }
    }

    public class Ship : AWeaponsPlatform, IMapObject
    {
        #region private data
        AMapObject _mapObjectHelper; // utilize services of AMapObject by aggregation rather than inheritance
        #endregion

        public Point3D Location
        {
            get
            {
                return _mapObjectHelper.Location;
            }
            set
            {
                _mapObjectHelper.Location = value;
            }
        }

        protected override void ShootImpl()
        {
            throw new NotImplementedException();
        }
    }

    public class MapObjectManager  // class to demo lists....
    {
        #region private data
        List<IMapObject> _mapObjects = new List<IMapObject>();
        #endregion

        public int Add(IMapObject newObject)
        {
            _mapObjects.Add(newObject);
            return _mapObjects.Count;
        }

        public List<IMapObject> Objects
        {
            get
            {
                return _mapObjects;
            }
        }

        public static void ExampleMethod() // intended to demonstrate use of a list
        {
            MapObjectManager mgr = new MapObjectManager();
            int firstCount = mgr.Add(new Planet()); // firstCount should == 1
            int secondCount = mgr.Add(new Ship()); // secondCount should == 2

            foreach (IMapObject obj in mgr.Objects)
            {
                Point3D thisLocation = obj.Location;
                // do something with thisLocation
            }

        }
    }

(Ok - I got kind of carried away with the example code, but it's just so easy to rattle off with the IDE :-) )

Any of your concrete map objects, e.g. planet, missile, ship, can derive from AMapObject (which you'll notice doesn't actually have any abstract or virtual methods), or if they need to derive from something else that's more useful, they can still implement the IMapObject interface.  This is demonstrated above by Planet (which derives from AMapObject) and Ship, which derives from the presumably more useful AWeaponsPlatform object.  The MapObjectManager class is intended to give examples of how to create a list of IMapObject objects and then use them in a foreach loop.

BTW, in the IDE, the "tab" key is your friend - most times you only need to hit about 2 keystrokes before you can tab and get auto-completion.  You can also right-click on the stuff after the ":" e.g. IMapObject and the IDE will fill in stubbed out routines which implement the interface or abstract class.

I think that this is enough for this one - going to go answer some other posts now....

John
 

Offline sloanjh

  • Global Moderator
  • Admiral of the Fleet
  • *****
  • Posts: 2805
  • Thanked: 112 times
  • 2020 Supporter 2020 Supporter : Donate for 2020
    2021 Supporter 2021 Supporter : Donate for 2021
Re: Programming Advice
« Reply #14 on: October 13, 2010, 12:25:35 AM »
This is a function which I am going to use to load Ship objects into a collection. At the moment, the assignment to a collection isn't in the code but it will be within the forearch loop. The problem is that the code never reaches the foreach loop. I have no runtime errors and no compilation errors. I do have breakpoints on the statement above the foreach loop and on the foreach loop itself. The breakpoint is triggered for the statement above but the foreach breakpoint is never triggered. For some reason the code doesn't get there, although the form that is calling this function loads without any problem. Any suggestions?

Are you sure it's not throwing in the GetDataByGame(1) call?  Note that by default Visual Studio doesn't turn on most exceptions - you have to go into Debug/Exceptions (or something like that) and click the appropriate checkbox.

The only other thing I can think of is that there aren't any ShipRows in ShipData, but that doesn't make a lot of sense because my experience is that VS-for-C# is a lot more anal about stepping through the various evaluations in a foreach statement - you can sit on the foreach line for 2-3 pushes of F10.

What happens if you go to your breakpoint and then start hitting F10?  If it exits, then I suspect that you've got a throw that VS isn't stopping on (like I said a paragraph or two back).

John