saving collections in Settings.Settings

I

Irfan

hi,

I wanted to save a simple collection in Settings.Settings but i am not able
to retrieve it.

Although no errors while saving it but no value are retrieved either.
Do i have to do something different.Am i missing something?

This is what i do;
SortedList x = new SortedList();
x.Add(1, 1);
x.Add(2, 2);
x.Add(3, 3);
Properties.Settings.Default.lst = x;
Properties.Settings.Default.Save();

Regards,
Irfan
 
I

Irfan

thanks Kevin, The collection is a collection of integers only. There are no
classes as such.

This is a simple example

SortedList x = new SortedList();
x.Add(1, 1);
x.Add(2, 2);
x.Add(3, 3);
Properties.Settings.Default.lst = x;
Properties.Settings.Default.Save();
 
K

Kevin Spencer

Of course there is a class. It is an instance of
System.Collections.SortedList. You need to create a member of the Settings
class that is a SortedList.

When you refer to

Properties.Settings.Default.lst

You are referring to a member of a class (Properties.Settings.Default). The
member must exist in order to assign a value to it.

Application Settings must be serializable in order to be stored in the
application configuration file. I don't believe that
System.Collections.SortedList is serializable straight out of the box, but
it might be. Take a look at the following article about Application Settings
Architecture for help. It is possible to serialize *anything* as text, if
you implement your own serializer:

http://msdn2.microsoft.com/en-us/library/8eyb2ct1.aspx
--
HTH,

Kevin Spencer
Microsoft MVP
Bit Player
http://unclechutney.blogspot.com

Expect the unaccepted.
 
I

Irfan

Kevin
Many thanks for your replies,

irfan

Kevin Spencer said:
Of course there is a class. It is an instance of
System.Collections.SortedList. You need to create a member of the Settings
class that is a SortedList.

When you refer to

Properties.Settings.Default.lst

You are referring to a member of a class (Properties.Settings.Default).
The member must exist in order to assign a value to it.

Application Settings must be serializable in order to be stored in the
application configuration file. I don't believe that
System.Collections.SortedList is serializable straight out of the box, but
it might be. Take a look at the following article about Application
Settings Architecture for help. It is possible to serialize *anything* as
text, if you implement your own serializer:

http://msdn2.microsoft.com/en-us/library/8eyb2ct1.aspx
--
HTH,

Kevin Spencer
Microsoft MVP
Bit Player
http://unclechutney.blogspot.com

Expect the unaccepted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top