Use of unassigned local variable 'dictionary'

Posted by codemonkie on Stack Overflow See other posts from Stack Overflow or by codemonkie
Published on 2010-06-18T01:57:46Z Indexed on 2010/06/18 2:03 UTC
Read the original article Hit count: 358

Filed under:
|

I got the error Use of unassigned local variable 'dictionary' despite I assigned the value in the following code:

private static void UpdateJadProperties(Uri jadUri, Uri jarUri, Uri notifierUri)
    {
        Dictionary<String, String> dictionary;

        try
        {
            String[] jadFileContent;

            // Create an instance of StreamReader to read from a file.
            // The using statement also closes the StreamReader.
            using (StreamReader sr = new StreamReader(jadUri.AbsolutePath.ToString()))
            {
                Char[] delimiters = { '\r', '\n' };
                jadFileContent = sr.ReadToEnd().Split(delimiters, System.StringSplitOptions.RemoveEmptyEntries);
            }

            // @@NOTE: Keys contain ": " suffix, values don't!
            dictionary = jadFileContent.ToDictionary(x => x.Substring(0, x.IndexOf(':') + 2), x => x.Substring(x.IndexOf(':') + 2));

        }
        catch (Exception e)
        {
            // Let the user know what went wrong.
            Console.WriteLine("The file could not be read:");
            Console.WriteLine(e.Message);
        }

        try
        {
            if (dictionary.ContainsKey("MIDlet-Jar-URL: "))
            {
                // Change the value by Remove follow by Add

            }
        }
        catch (ArgumentNullException ane)
        {

            throw;
        }

    }

The error is from the line:

if (dictionary.ContainsKey("MIDlet-Jar-URL: "))

Can any one help me out here, pls? TIA

© Stack Overflow or respective owner

Related posts about c#

Related posts about dictionary