Note that there are some explanatory texts on larger screens.

plurals
  1. POChange private string from another class
    primarykey
    data
    text
    <p>I'm wondering as to why my private variable 'name' within my Events class won't change when I access the property from my Leisure class which inherits from Events. I need Leisure to use the properties to change it, and then in my form class, it should be able to read the value of 'name' from events. See below:</p> <pre><code>public partial class Form1 : Form //Main form class { private string eventType; //used for event type selection private string formEventName; //used to store selected event name private void itemSend_Click(object sender, EventArgs e) { //encapsulation Events myEv = new Events(); string name=itemInput.Text; myEv.myEvent(eventType, name); formEventName = myEv.myName; txtOutput.Text = "Event name is " + formEventName + "\r\n"; } class Events:Form1 { private string name; //private variable for event name public string myName //used to change property value depending on what eveny type/ event name { get { return name; } set { name = value; } } public void myEvent(string eventType, string eventName) //variable recieved from main form class { if (eventType == "Leisure") { Leisure myLes = new Leisure(); myLes.eventNames(eventName); } else { //test for other event types } } class Leisure:Events { public void eventNames(string eventName) { //when adding new items add one with a capital and one without myEventNames.Add("music"); myEventNames.Add("Music"); if (myEventNames.Contains(eventName)) { myName = eventName; } else { MessageBox.Show("item not found, please try again"); //error message } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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