Error cs1586 array creation must have array size or array initializer

I got this error with a .dll and I'm trying to fix it: https://pastebin.com/raw/tDDbb93n The error is on the following line: Logger.n("Saving {0}", new object[]); Thanks.

I got this error with a .dll and I’m trying to fix it:

https://pastebin.com/raw/tDDbb93n

The error is on the following line:

Logger.n("Saving {0}", new object[]);

Thanks.

jww's user avatar

jww

95k88 gold badges397 silver badges861 bronze badges

asked Sep 21, 2018 at 5:02

Bills The God Of Destruction's user avatar

2

Hello and Welcome to Stack Overflow! It is quite simple actually: all you have to do is to declare the size of your array on the line you create and use it. Instead of new object[] you could try new object[32]. (or any size that helps you)

Hope this helps! ^^

answered Sep 21, 2018 at 5:11

Gabriel Stancu's user avatar

Gabriel StancuGabriel Stancu

9102 gold badges15 silver badges26 bronze badges

You need to specify the size of the object array.

Try this:
Logger.n("Saving {0}", new object[10]);

answered Sep 21, 2018 at 5:11

jeninja's user avatar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
 
namespace lab09_hotamovha
{
    public partial class Running : Form
    { 
        Thread c3po1;
        Thread droid1;
        Thread r2d21;
        Thread droideka1;
        Thread probe_droid1;
 
        Random random;
 
       PictureBoxComparable [] pictureBoxes;
 
        public delegate void HelpToCall(PictureBox pictureBox);
        HelpToCall helper;
        
        public Running()
        {
            random= new Random();
            helper = new HelpToCall(Motion);
            InitializeComponent();
            pictureBoxes = new PictureBoxComparable[] { c3po, droid, r2d2, droideka, probe_droid };
        }
 
        private void startbtn_Click(object sender, EventArgs e)
        {
            if (c3po1 == null)
            {
                c3po1 = new Thread(Movement1);
                c3po1.IsBackground = true;
                c3po1.Start();
 
                droid1 = new Thread(Movement2);
                droid1.IsBackground = true;
                droid1.Start();
 
                r2d21 = new Thread(Movement3);
                r2d21.IsBackground = true;
                r2d21.Start();
 
                droideka1 = new Thread(Movement4);
                droideka1.IsBackground = true;
                droideka1.Start();
 
                probe_droid1 = new Thread(Movement5);
                probe_droid1.IsBackground = true;
                probe_droid1.Start();
            }
            else
            {
                c3po1.Resume();
                droid1.Resume();
                r2d21.Resume();
                droideka1.Resume();
                probe_droid1.Resume();
            }
            startbtn.Enabled = false;
            
            susbtn.Enabled = true;
            stopbtn.Enabled = true;
        }
        void Motion(PictureBox pictureBox)
        {
            pictureBox.Location = new Point(pictureBox.Location.X + random.Next(1,10), pictureBox.Location.Y);
            Lider();
        }
 
        private void Lider()
        {
            Array.Sort(pictureBoxes);
            pictureBoxes[0].BackColor = Color.Yellow;
            for (int i=1;i<pictureBoxes.Length;i++)
                pictureBoxes[i].BackColor =SystemColors.Control;
        }
 
        void Movement1()
        {
            while (true)
            {
                Invoke(helper,c3po);
                Thread.Sleep(random.Next(30,100));
            }
        }
        void Movement2()
        {
            while (true)
            {
                Invoke(helper,droid);
                Thread.Sleep(random.Next(30, 100));
            }
        }
        void Movement3()
        {
            while (true)
            {
                Invoke(helper, r2d2);
                Thread.Sleep(random.Next(30, 100));
            }
        }
        void Movement4()
        {
            while (true)
            {
                Invoke(helper,droideka);
                Thread.Sleep(random.Next(30, 100));
            }
        }
        void Movement5()
        {
            while (true)
            {
                Invoke(helper, probe_droid);
                Thread.Sleep(random.Next(30, 100));
            }
        }
 
        private void susbtn_Click(object sender, EventArgs e)
        {
            if (c3po1!=null)
            {
                c3po1.Suspend();
                droid1.Suspend();
                r2d21.Suspend();
                droideka1.Suspend();
                probe_droid1.Suspend();
            }
            resbtn.Enabled = true;
        }
 
        private void stopbtn_Click(object sender, EventArgs e)
        {
            susbtn_Click(sender, e);
            Reset();
            startbtn.Enabled = true;
            resbtn.Enabled = false;
            susbtn.Enabled = false;
            stopbtn.Enabled = false;
        }
 
        private void Reset()
        {
            c3po.Location = new Point(12, c3po.Location.Y);
            droid.Location = new Point(12, droid.Location.Y);
            r2d2.Location = new Point(12, r2d2.Location.Y);
            droideka.Location = new Point(12, droideka.Location.Y);
            probe_droid.Location = new Point(12, probe_droid.Location.Y);
            foreach (PictureBoxComparable pb in pictureBoxes)
                pb.BackColor = SystemColors.Control;
        }
 
        private void resbtn_Click(object sender, EventArgs e)
        {
            if (c3po1 != null)
            { 
                c3po1.Resume();
                droid1.Resume();
                r2d21.Resume();
                droideka1.Resume();
                probe_droid1.Resume();
            }
            resbtn.Enabled = false;
        }
 
        private void Running_FormClosing(object sender, FormClosingEventArgs e)
        {
            susbtn_Click(sender, e);
        }
    }
}

User-79560820 posted

Hello,

I am having issues creating a multidimensional array. In PHP I built this really nice function that will loop through an SQL query and return a 2-dimensional array of key name and values. In doing this I am able to extract my data like this:

echo $var[0][«field_name»];

However in C# I am having issues getting this to work.

I am trying to do it like this:

string[,] keyArray = new string[,];

but this is throwin an error:
CS1586: Array creation must have array size or array initializer.

The issue that I’ve been having is that I want to create a 2-D array but I dont know what the size will be when I’m done. Is it possible to create a completely empty 2-D array in C#?

If anyone is needing the PHP to see function here it is:

        function return_values($q)
        {
            $keyarr = array();

            
            for($i = 0; $i < mysql_num_rows($q); $i++)
            {
                $r = mysql_fetch_assoc($q);
                foreach($r as $key => $val)
                {
                    $keyarr[$i][$key] = $val;
                }
            }
            return($keyarr);
        }

Понравилась статья? Поделить с друзьями:
  • Error cs1529 unity
  • Error cs1525 unexpected symbol void
  • Error cs1525 unexpected symbol public
  • Error cs1525 unexpected symbol expecting
  • Error cs1525 unexpected symbol end of file