Quantcast
Viewing all articles
Browse latest Browse all 107

C# Dictionary protection level when foreach-ing

Here's the error: error CS0122: `System.Collections.Generic.KeyValuePair.Value' is inaccessible due to its protection level Here's the code that triggers it: using UnityEngine; using System; using System.Collections; using System.Collections.Generic; using System.IO; public class HSInventoryManager : MonoBehaviour { public Dictionary InventoryItemsDictionary = new Dictionary(); public void Start (){ //First, populate dictionary contents with items the player MIGHT have. InventoryItemsDictionary.Add("Hydrogen", 0); InventoryItemsDictionary.Add("Helium", 0); InventoryItemsDictionary.Add("Lithium", 0); // And so forth bool PlayerPrefsNeedUpdate = false; //Second, update the dictionary contents with savegame data wherever it exists, create entries otherwise foreach( KeyValuePair InventoryItemDictionaryEntry in InventoryItemsDictionary ) { if( PlayerPrefs.HasKey( InventoryItemDictionaryEntry.Key )) { InventoryItemDictionaryEntry.Value = PlayerPrefs.GetInt( InventoryItemDictionaryEntry.Key ); } else { PlayerPrefs.SetInt(InventoryItemDictionaryEntry.Key, InventoryItemDictionaryEntry.Value); PlayerPrefsNeedUpdate = true; } } // Third, update savegame data with the fresh inventory levels, if needed. if ( PlayerPrefsNeedUpdate ) { PlayerPrefs.Save(); } } } I have declared everything public that I can identify... so why would there be a protection level problem? Thank you for your guidance.

Viewing all articles
Browse latest Browse all 107

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>