Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <code>myName</code> property you are using changes the <code>name</code> private field of myLes instance and not the name private field of myEv instance created in the ItemSend_Click.</p> <p>In an Object Oriented Language when you create an instance of a class, that instance has a copy of every non-static private/public variable declared in the class. So when you write</p> <pre><code> Leisure myLes = new Leisure(); </code></pre> <p>you are creating an instance of Leisure class, but this instance, while inherithing from Events has a different set of internal variables and not the same variables of the current Event instance (myEv).</p> <p>Looking at your code I suggest to create a third class called</p> <pre><code>public class EventFactory { public Event CreateEvent(string eventType, string eventName) { switch(enventType) { case "Leisure": Leisure myLes = new Leisure(); myLes.eventNames(eventName); return myLes; // case Add other specialized events here: // break; default: return null; } } } </code></pre> <p>change your Events class removing the inheritance from Form1 (not needed as far as I can tell) and the method myEvent</p> <p>now your ItemSend_Click could be written in this way</p> <pre><code>private void itemSend_Click(object sender, EventArgs e) { Events myEv = new EventFactory().CreateEvent(eventType, itemInput.Text); formEventName = myEv.myName; txtOutput.Text = "Event name is " + formEventName + "\r\n"; } </code></pre> <p>this works because <code>Leisure</code> derives from <code>Events</code> and you could treat every Leisure instance as an Event instance.</p>
 

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