forum

Home / DeveloperSection / Forums / Using Key Value Pair with lists to dynamically create a paired value array

Using Key Value Pair with lists to dynamically create a paired value array

Anonymous User 2284 14-Aug-2014

I'm currently using XDocument to read specific attributes from a XML Document, This works without a hitch. Now, I'm trying to create an array with Keys and Values to be later used for Validation. This may be an isolated incident (due to being unable to google/research the errors) , but the error messages which I am experiencing has totally stumped me, the syntax does look correct. The code follows:

    public Array GetConfig(string FilePath)
    {
            var Document = XDocument.Load("CoreConfig.xml");
            var Results = Document.Descendants().Elements("Database");
            var ReturnList = new List<KeyValuePair<string,string>>();
                string[] DBConfigElements = new string[4]{"Server","Username","Password","Database"};
                int Count = 1;
                var list = new List<KeyValuePair<string, string>>() { // Errors 1,2,3
                foreach (string Elements in Results){
                    new KeyValuePair<string,string>(DBConfigElements[Count],Elements);
                    Count++;
                } // Error 4
            };
      }

The error messages Presented are:

Error 1 Invalid initializer member declarator

Error 2 ; expected

Error 3 } expected

Error 4 { expected

I have labeled the code which line the error message is being triggered from. The syntax does look correct, so where is it that I am going wrong?


c# c# 
Updated on 14-Aug-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By