Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8982085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:29:54+00:00 2026-06-15T20:29:54+00:00

I managed to write to and read a specific parameter from a .ini file.

  • 0

I managed to write to and read a specific parameter from a .ini file.
I was wondering if there was a way to load the entire content of the .ini file and store it in a special class. That way, I only have to load the .ini file once. This way it should reduce the amount of loading that the game will do.

I know that in small games, it propably doesn’t matter, but I would still appreciate it if someone could point me in the right direction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:29:57+00:00Added an answer on June 15, 2026 at 8:29 pm

    Assuming the INI is a simple key / value pair split with new line could you use something like this to provide the entire INI file as either a dictionary or a strongly typed object.

    the method allows you to load an ini file into an object like this.

    class IniStructure
    {
        public short Field1;
        public int Property1 { get; set; }
        public string Property2 { get; set; }
    }
    
    IniStructure ini = IniLoader.Load<IniStructure>(<fileName>);
    

    or simply in to a dictionary with the non T method.

    public static class IniLoader
        {
            public static T Load<T>(string fileName)
            {
                T results = (T)Activator.CreateInstance(typeof(T));
    
                PropertyInfo[] tProperties = typeof(T).GetProperties();
                FieldInfo[] tFields = typeof(T).GetFields();
    
                var iniFile = Load(fileName);
    
                foreach (var property in tProperties)
                    if (iniFile.ContainsKey(property.Name))
                    {
                        object s = System.Convert.ChangeType(iniFile[property.Name].ToString(), property.PropertyType);
                        property.SetValue(results, s, null);
                    }
                foreach (var field in tFields)
                    if (iniFile.ContainsKey(field.Name))
                    {
                        object s = System.Convert.ChangeType(iniFile[field.Name].ToString(), field.FieldType);
                        field.SetValue(results, s);
                    }
    
                return results;
            }
    
            public static Dictionary<string, object> Load(string fileName)
            {
                Dictionary<string, object> results = new Dictionary<string, object>();
    
                string fileText = File.ReadAllText(fileName);
                string[] fileLines = fileText.Split('\r');
                if (fileLines.Length > 0)
                    for (int i = 0; i < fileLines.Length; i++)
                    {
                        string line = fileLines[i].Trim();
                        if (!string.IsNullOrEmpty(line))
                        {
                            int equalsLocation = line.IndexOf('=');
                            if (equalsLocation > 0)
                            {
                                string key = line.Substring(0, equalsLocation).Trim();
                                string value = line.Substring(equalsLocation + 1, line.Length - equalsLocation - 1);
    
                                results.Add(key, value);
                            }
                        }
                    }
    
                return results;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK, I managed to read from an XML file using NSXMLParser , but now
Here comes again, I have managed to collect specific data from resx file (xml)
Can .NET (managed code) read and write to CouchDB? I would like to build
I trying to write a simple function to call unmanaged code from managed code.
I am trying to write a Java applet that will read from a user's
I am trying to write a c++ program that would read key frames from
I managed to write add program that upon the user click a button, he
i managed to write the data to a single column. My req is to
So far I have managed to write some code that should print the source
I'm trying to write a managed library in C# that will act as an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.