joe_pool_is Posted May 21, 2009 Posted May 21, 2009 I've got a 8x8 array. Each element of the array will contain an object that consists of a letter, a color, and a double value. Creating and working with arrays in my class is not the hard part. The hard part is how do I make them publicly accessible outside of my class? In other words, how would I write the Get and Set properties for it? I'm guessing I should not be using the standard 8x8 array, and instead I should be using ...what? And, how would I implement it? I'm looking to stay within Microsoft's Best Practices, if I can. As always, help, links or advice is always appreciated! Quote Avoid Sears Home Improvement
DPrometheus Posted May 22, 2009 Posted May 22, 2009 Hey there for single arrays you can use this: Default Public ReadOnly Property Item(ByVal index As Integer) As Object Get Return List(index) End Get End Property If you want to use an array of more items you can go for an implementation with 'rows' in your array. Create a class or structure which contains a single row of 8 items. then you can modify it to something like this: Default Public Property Item(ByVal index As Integer) As ArrayRow8 Get dim r as new ArrayRow8(.. input data from array8x8(index) .. ) Return r End Get Set(byval value as ArrayRow8) array8x8(index) = value ' You have to specify an operator overload or copy this per value. Return r End Get End Property however I must confess I don't know if it's a Microsoft Best Practice, but that's how I solved it in the past. Hope it helps. ~DP Quote My Development System Intel Core i7 920 @2.66Ghz 6 GB DDR3 SDRAM Windows 7 Ultimate x64 & Windows Vista Home Premium x64 dual boot GeForce GTX295 1.8 GB 3.5 TB HD
joe_pool_is Posted May 22, 2009 Author Posted May 22, 2009 That got me started. Thanks! Along the way, I found this technique that looks really clean: public class FormValues { int otherValue; string[,] matrix; public string this[int X, int Y] { get { return matrix[X, Y]; } set { matrix[X, Y] = value; } } public FormValues() { otherValue = 0; matrix = new int[8, 8] { // blah blah blah! } public int Other { get { return otherValue; } } } Quote Avoid Sears Home Improvement
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.