Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your code, you are <a href="http://msdn.microsoft.com/en-us/library/vstudio/dd460654.aspx#InstantiatingClasses" rel="nofollow">instantiating</a> your second class, <code>BankAccount</code> with this line:</p> <pre><code>BankAccount a = new BankAccount(); </code></pre> <p>But, you aren't using it anywhere. Based on what you have said in your original post, to get to the properties in your second class, you would call them like this:</p> <pre><code>a.IBa; a.Num1; a.withDrawl; </code></pre> <p>Below is a VERY simplistic example:</p> <pre><code>namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string aValue = String.Empty; Something a = new Something(); a.SomeThingElse = aValue; } } public class Something { public string SomeThingElse { get { return SomeThingElse; } set { SomeThingElse = value; } } } } </code></pre> <p>In the example above, you can see that I am instantiating my new class <code>public class Something</code> in the <code>button1_Click</code> event, then calling the property within it by using <code>a.SomethingElse = aValue</code>, which is a <code>string</code> I have defined in the initial class. In this case, <code>aValue=""</code> because it was initialized to <code>String.Empty</code>, which is '""'.</p> <p>Also, on a side note, you may want to set the abstraction level on your second class to <code>public</code>, because without declaring it <code>public</code>, it will default to <code>private</code> (which would not cause issues in this case - it's just something to keep in mind).</p> <p>I am adding in another example - this one using some of the code you have provided:</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void dep_Click(object sender, EventArgs e) { try { decimal newBalance; BankAccount bankAccount = new BankAccount(); // Instantiate your class. bankAccount.DepositAmount = Convert.ToDecimal(depAmt.Text); newBalance = (Convert.ToDecimal(currentBalance.Text)) + bankAccount.DepositAmount; currentBalance.Text = newBalance.ToString(); } catch { MessageBox.Show("ERROR", "Oops, this isn't good!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } public class BankAccount { decimal depositAmount; public decimal DepositAmount { get { return depositAmount; } set { depositAmount = value; } } } } </code></pre>
    singulars
    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.
    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