0

I have a settings property which is a "string[][]" (a string array built of string arrays) inside my Properties.Settings.Default. I set it up like this, and it seems as VS reads it properly:

<Setting Name="Markers" Type="System.String[][]" Scope="User">

Here is my code:

string[][] buttons = (string[][])Properties.Settings.Default.Markers;
buttons[0] = new string[] { "pause", "", "0", "255", "0" }; // Object reference not set to an instance of an object - here

buttons[1] = new string[] { "pause", "", "0", "255", "0" };

buttons[2] = new string[] { "effect", "", "255", "0", "0" };

buttons[3] = new string[] { "interest", "", "255", "255", "0" };

buttons[4] = new string[] { "cut", "", "0", "255", "255" };

The rest of the code is not related to Properties.Settings.Default.Markers. I just started dealing with this

edit: I found that buttons is a null... The only way I found to initialize it is this: Properties.Settings.Default.Markers = new string[100][]; the problem is it has a max of 100 arrays in it. My question is is there any way to initialize it without setting a length?

Matan
  • 456
  • 2
  • 8
  • 18
  • 1
    that is not a _two dimensional_ array, you have a _jagged_ array. – Selman Genç May 08 '14 at 20:55
  • Yea... I googled that and it seems like that's what I meant actually, an array of arrays... – Matan May 08 '14 at 20:59
  • Have you used a debugger to see what the buttons variable is set to in the first line of code? As the only thing that can really cause the error on the second line, is that buttons == null. – Håkan Fahlstedt May 08 '14 at 21:07
  • so your buttons object is null? buttons has the string[][] type but I don't see that it is initialized from your example. – Kunukn May 08 '14 at 21:09
  • Almost all cases of `NullReferenceException` are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders May 08 '14 at 21:25
  • It is indeed a null... I have checked that and thank you for answering but the only way I found to initialize it is this: Properties.Settings.Default.Markers = new string[100][]; the problem is it has a max of 100 arrays in it. my question is is there any way to initialize it without setting a length? – Matan May 08 '14 at 21:27
  • Is there a reason you need to use arrays? Why not a List? That would not need a size at initialization. – 7200rpm May 08 '14 at 22:10
  • I couldn't find a way online to use Lists in the Property.Settings.Default ... That was the first thing I tried... – Matan May 09 '14 at 03:25
  • I continued searching and finally came across something... I'm posting my answer. – Matan May 09 '14 at 05:57

1 Answers1

0

I continued searching quite a lot and found this: How to store a list of objects in application settings

This answered my questions and helped me a lot

Community
  • 1
  • 1
Matan
  • 456
  • 2
  • 8
  • 18