Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does .NET have an equivalent to Java's .properties files?

Tags:

To jog everyone's memory, Java has these files with an extension of ".properties", which are basically an ASCII text file full of key-value pairs. The framework has some really easy ways to suck that file into (essentially) a fancy hashmap.

The two big advantages (as I see it) being extreme ease of both hand-editing and reading/writing.

Does .NET have an equivalent baked in? Sure, I could do the same with an XML file, but I'd rather not have to hand type all those angle brackets, if you know what I mean. Also, a way to suck all the data into a data structure in memory in one line is nice too.

(Sidebar: I kind of can't believe this hasn't been asked here already, but I couldn't find such a question.)

Edit:

To answer the question implied by some of the comments, I'm not looking for a way to specifically read java .properties files under .NET, I'm looking for the functional equivalent in the .NET universe. (And I was hoping that it wouldn't be XML-based, having apparently forgotten that this is .NET we're talking about.)

And, while config files are close, I need way to store some arbitrary strings, not app config information, so the focus and design of config files seemed off-base.

like image 227
Electrons_Ahoy Avatar asked Jan 30 '10 22:01

Electrons_Ahoy


People also ask

What language is a .properties file?

properties is a file extension for files mainly used in Java-related technologies to store the configurable parameters of an application. They can also be used for storing strings for Internationalization and localization; these are known as Property Resource Bundles.


2 Answers

You can achieve a similar piece of functionality to properties files using the built in settings files (in VS, add a new "Settings file") - but it is still XML based.

You can access the settings using the auto-generated Settings class, and even update them and save them back to the config file - all without writing any of the boilerplate code. The settings are strongly-types, and can be specified as "User" (saved to the user's Application Data folder) or "Application" (saved to the same folder as the running exe).

like image 130
adrianbanks Avatar answered Sep 18 '22 13:09

adrianbanks


The .NET way is to use a configuration file. The .NET framework even offers an API for working with them.

like image 30
Andrew Hare Avatar answered Sep 17 '22 13:09

Andrew Hare