1

I'm trying to read it multiple settings files that I'm using as player settings. C# and XNA

They all have the exact same setup. AKA Settings1 has player1's Name, ShipType, Weapon, Shield, Color, etc... (about 100 things) Settings2 has player2's Info, Setup identically as player 1.AkA Settings1.settings Settings2.settings etc...
I'm using this because it lets me easily reference everything in VS and I can just click to add stuff and it figures out types and all that good stuff for me.

This is what I want to do

{
    System.Configuration.ApplicationSettingsBase[] playerSettings;

    playerSettings = new System.Configuration.ApplicationSettingsBase[2];

    playerSettings[0] = Settings1.Default;
    playerSettings[1] = Settings2.Default;

    string player1Name = playerSettings[0].Name;
    string player2Name = playerSettings[1].Name;
}

However. if I use this setup playerSettings[0] does not let me access the Name property.

When I go into debug I can see that PlayerSettings[0] Contains the Settings1 and inside it is the Name property. I just cant figure out how to access it in VS so I can read it in.

-       [0] {WindowsGame3.Settings1} System.Configuration.ApplicationSettingsBase {WindowsGame3.Settings1}
-       [WindowsGame3.Settings1]    {WindowsGame3.Settings1} WindowsGame3.Settings1
+       base    {WindowsGame3.Settings1} System.Configuration.ApplicationSettingsBase {WindowsGame3.Settings1} Name "sally" string

I had hoped to be able to use the system.configureation.applicationsettingsbase[] so that I could simply pass it to the method and only have to update the code there 1 time. rather then manually doing it fore each player(right now that's 4 times and its very long)

Again, these need to be the default Settings files that you can add to the project by right clicking and selecting add-new-settings.

TLDR: I need a way to access properties inside an array of System.Configuration.ApplicationSettingsBase, that is full of .settings files. OR Pass each different .settings file to a method even though they are recognized as different types Thanks

jcsanyi
  • 8,133
  • 2
  • 29
  • 52
Krell
  • 55
  • 1
  • 6

1 Answers1

2

File.Exists sees if a specific file exists.
There are several ways of testing file existence. File.Exists is the easiest. It is the simplest way of checking that the file exists, it returns true or false.

Navnath Godse
  • 2,233
  • 2
  • 23
  • 32
  • Thanks for the response Navnath. I guess I was not clear. I already checked and know the file exists and if I go into the debugger I know that its loaded with my data, I just can't access that data. Again, string player1Name = playerSettings[0].Name; the .Name part of that statement does not work. when I type in string player1Name = playerSettings[0] and then type . "Name" is not on the list. and the debug view shows that playerSettings[0] is a windowsGame3.Settings which should have .Name This is also true of the other elements. such as .Weapon .Ship etc... – Krell Jun 08 '13 at 02:42