HSN Posted May 2, 2004 Posted May 2, 2004 Hello, This is my first post in this forum... and I hope that I find the proper answer my question :) I think that I have to talk about my problem right in this forum... anyway my problem is with the following code: I'm a C/C++ programmer and I loop at C# as a C programmer point of you, thus I tried to initialize a 2D array as follows: using System; namespace CSharp_Scanner { class scanner { static int [][] array = { {1,2}, {3,4} }; static void Main(string[] args) { } } } but it tells that: Array initializer can only be used in a variable or a field initializer. So please can anyone help me with initializing my array inside a class...? ;) Quote
Administrators PlausiblyDamp Posted May 2, 2004 Administrators Posted May 2, 2004 To create a 2D array use static int[,] array = { {1,2}, {3,4} }; the int[][] syntax declares a jagged array General info on the types of arrays found in c# can be found here Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
HSN Posted May 2, 2004 Author Posted May 2, 2004 oh thanks PlausiblyDamp I just forgot to create the 2d array like that. Thank you very much... :) Quote
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.