joe_pool_is Posted January 22, 2004 Posted January 22, 2004 I have tried to innitialize an array all in one step, like this: intArray() = {1, 2, 3, 4, 5} or intArray = {1, 2, 3, 4, 5} or many other methods similar. Nothing seems to work. The only way I have managed to populate the elements of the array is: intArray(0) = 1 intArray(1) = 2 intArray(2) = 3 intArray(3) = 4 intArray(4) = 5 Is there a more elegant method? Quote Avoid Sears Home Improvement
Administrators PlausiblyDamp Posted January 22, 2004 Administrators Posted January 22, 2004 Dim intArray() As Integer = {1, 2, 3, 4, 5, 6} int[] intArray = {1,2,3,4,5,6}; Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
joe_pool_is Posted January 22, 2004 Author Posted January 22, 2004 Does this only work when the array is innitialized? I've tried: dataout = {0, 1, 2, 3, 4, 5, 6} dataout() = {0, 1, 2, 3, 4, 5, 6} The first one gives me "Expression expected." at the first curley brace. The second attempt gives me "Number of indices is less than the number of dimensions of the indexed array." and "Expression expected." like before. Quote Avoid Sears Home Improvement
splice Posted January 22, 2004 Posted January 22, 2004 afaik you can only assign an array like that when it's declared. look into Array copying. Class X Protected Shared arr As Integer = {0,0,1,2,1,23,5} Public Sub New() Dim y As Integer() y = DirectCast(arr.Clone(), Integer()) '' or ReDim y(arr.Length() - 1) arr.CopyTo(y, 0) End Sub End Class Quote -=splice=- It's not my fault I'm a Genius!
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.