Note that there are some explanatory texts on larger screens.

plurals
  1. POObject instance is overwriting the other instance but I cant see why
    text
    copied!<p>I was wondering if you could look at my code and see where I have gone wrong. Basically, I have created an object of type "UserFile"(my own object type) and am creating 2 instances of it and within the constructor of that object, I am calling a static class method. All goes well for them except the second instance overwrites the first one after the object constructor is called. I have stepped through the program and am thoroughly confused. I get the feeling im missing something very obvious here.</p> <p><strong>Here is the button on the form that creates the instances</strong></p> <pre><code> private void btnCompare_Click(object sender, EventArgs e) { if (lstFiles.CheckedItems.Count == 2) { file1 = new UserFile(((FileLocation)lstFiles.CheckedItems[0]).filePath); file2 = new UserFile(((FileLocation)lstFiles.CheckedItems[1]).filePath); } } </code></pre> <p><strong>Here is the UserFile class with constructor</strong></p> <pre><code>public class UserFile { public Dictionary&lt;int,Individual&gt; fileIndividuals; public Dictionary&lt;int, Family&gt; fileFamilies; public Header fileHead; public UserFile(string _dir) { fileIndividuals = new Dictionary&lt;int, Individual&gt;(); fileFamilies = new Dictionary&lt;int, Family&gt;(); fileHead = new Header(); ReadFromFile.Read(_dir); fileIndividuals = ReadFromFile.individuals; fileFamilies = ReadFromFile.families; fileHead = ReadFromFile.head; } } </code></pre> <p><strong>Here is the ReadFromFile method called by the UserFile class</strong></p> <pre><code>static class ReadFromFile { public static string filename = ""; public static Header head; public static Individual individual; public static Dictionary&lt;int, Individual&gt; individuals = new Dictionary&lt;int, Individual&gt;(); public static Family family; public static Dictionary&lt;int, Family&gt; families = new Dictionary&lt;int, Family&gt;(); public static GedcomRecordEnum currentRecord = GedcomRecordEnum.None; public static GedcomSubRecordEnum currentFirstLvlRecord = GedcomSubRecordEnum.None; public static GedcomSecondLevelEnum currentSecondLvlRecord = GedcomSecondLevelEnum.None; static public void Read(string fileName) { individuals.Clear(); families.Clear(); head = null; if (File.Exists(fileName)) { filename = fileName; StreamReader reader = new StreamReader(fileName); while (!reader.EndOfStream) { string currentLine = reader.ReadLine(); Match m = Regex.Match(currentLine, "(?&lt;index&gt;[0-9]) (?&lt;keyword&gt;[A-Z_@0-9]+)(?: *)(?&lt;detail&gt;.*)"); string debug = m.Groups["index"].ToString(); switch (m.Groups["index"].ToString()) { case "0": ProcessRootLevel(m.Groups["keyword"].ToString()); break; case "1": ProcessLevel1(m.Groups["keyword"].ToString(), m.Groups["detail"].ToString()); break; case "2": ProcessLevel2(m.Groups["keyword"].ToString(), m.Groups["detail"].ToString()); break; case "3": ProcessLevel3(m.Groups["keyword"].ToString(), m.Groups["detail"].ToString()); break; } } reader.Close(); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload