Search code examples
c#application-settings

Can I save an object to the app.config file?


I need to use a config file for my application which will save a list of details for each entity: for example-

<person A>
         <name= >
         <age= >
<person B>
         <name=>
         <age= >

is something of this sort possile in the settings class or this requires using the app.config file wihtout the settings class wrapper?

Edit: My application used to have a single entity, now it should support multiple entities and therefore save multiple entities in some config.


Solution

  • Yes, you can save any sort of information (strings) in .config file. You'd then use the ConfigurationManager class to access the saved information by using a Key.

    But why would you want to save information like this in the .config?

    I recommend you use an XML document for this purpose. You can then use the XDocument class to parse it.

    Edit:

    After reading your comment, I think the app.config file cannot save an object. So you could not save a class object there.