I am unable to determine why the code here will not compile in MonoDevelop 2.8.2 on Win32 using Mono 2.10.6. Monodevelop indicates that found_image_paths is an unassigned local variable?
Am I missing something here? I am new to C#
string path = this.DirectoryChooser.CurrentFolder;
Console.WriteLine ("Selected Path: " + path);
//Iterate over all DAE files in this folder
string[] model_paths = Directory.GetFiles(path,"*.dae");
HashSet<string> found_image_paths;
foreach (string dae_path in model_paths)
{
XmlDocument xmlDoc= new XmlDocument(); //* create an xml document object.
xmlDoc.Load(dae_path); //* load the XML document from the specified file.
//* Get elements.
XmlNodeList library_images = xmlDoc.GetElementsByTagName("library_images");
System.Console.WriteLine(dae_path);
foreach (XmlNode image_node in library_images[0].ChildNodes) {
string image_path = image_node.FirstChild.InnerText;
found_image_paths.Add(image_path);
Console.WriteLine(image_path);
}
}
//The next line returns the error "Use of unassigned local variable 'found_image_paths'
foreach (var item in found_image_paths) {
Because it is unassigned; you need to instantiate a hashset and assign it to your variable or at least assign it
null.