[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

proper syntax??

What is the proper syntax to use here?
How do I inject integers row & col into my statement to direct the code to increment which matrix variable it needs to display? (eg. myMatrix.M11, myMatrix.M12, myMatrix.M13, etc are fields within myMatrix)


            for (int row = 1; i < 5; row++)
            {
               
                for (int col = 1; j < 5; col++)
                {
                    frameFont.DrawText(null, Convert.ToInt16(MyMatrix.M    row???    col???     ).ToString(), new Point(mStartHortz,mStartVert), Color.White);
                    mStartHortz += spH;
                }
                mStartVert += spV;
            }
Thanks, Steve
0
OutsideTheBox
Asked:
OutsideTheBox
  • 2
  • 2
  • 2
1 Solution
 
dstanley9Commented:
There's no "easy" way as C# is compiled, not interpreted.

How many rows/columns are there?  If there are only a few, it may be cleanest tu use a CASE statement.

If there are many, the best way is to use reflection; the syntax will determing on the definition of the MyMatrix class e.g. are M1, M2, etc. properties (i.e. with get/set accessors) or fields (accessed directly)?

Here are some starting points:

http://msdn2.microsoft.com/en-US/library/ms173183.aspx
http://www.ondotnet.com/pub/a/dotnet/excerpt/prog_csharp_ch18/index.html?page=5

On a side note, did you develop the MyMatrix class?  If so, I would STRONGLY consider redoing it to use indexers instead of naming fields. They way you can use the syntax

myMatrix[row][column]

instead of reflecting.
0
 
OutsideTheBoxAuthor Commented:
Thanks,
there are 4 rows and 4 columns.

I can do it the long way I thought one statement would be clean. It is just for troubleshooting anyway, not for anything to be used.

No, not mine, it is a Microsoft class; Microsoft.Directx.Matrix
Programming with C++ using different DirectX classes it  uses indexers (Matrix[][]) but in managed DirectX they do not.

Thank you,
Steve
0
 
seaziumCommented:
frameFont.DrawText(null, Convert.ToInt16(MyMatrix.M[i][j]).ToString(), new Point(mStartHortz,mStartVert), Color.White);


dZ..,                  
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
dstanley9Commented:
Boy, talk about the ultimate in bounds-checking!  They must have done it that way either to eliminate bounds-checking for every element access or for memory effeciency since it's a value type (struct).
0
 
OutsideTheBoxAuthor Commented:
seazium,
I tried both M[][] and myMatrix[i,j](ref your link) neithe works with the DirectX Matrix. (also, my for() statement was corrected for the obvius i/row, j/col issue)
oh well, as usual, writing 12 lines took less time than trying to make the above code work. My 12 lines work fine & I've moved on.

Thanks guys,
Steve
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now