Results 1 to 2 of 2

Thread: I can't understand what I'm missing on (base) constructor on C#

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    166

    Question I can't understand what I'm missing on (base) constructor on C#

    Hi there everyone, as you can see I'm new to this forum, as this is my 1st post.
    I'm creating a small program (mostly for the fun of it) on C# and I have pratically everything working, but the part of where I need to get some results (as usual lol)
    So I decided to scrounge around the Web, to check for any clues on how to solve a problem I'm having and I came up with very thread.
    I'm having a bit of a problem on trying to understand how the inheritance works on C#, on Visual Basic I have no problems with and I'm doing fine on distinguishing the differences from VB to C#, but on my code I'm getting no results. At 1st I thought I was on the right path, but didn't get any results, so I tried to vary some stuff around and see if I'd get anywhere, but nothing. I've been using MrPolite's Thread to get the differences between VB and C#, but now I've hit a concrete wall when it comes to the My.Base constructor...

    Here's the code I have:

    [SPOILER]

    Code:
    //This is my class constructor
    public cTemp()
            {
                mSaldoCarteira = 50;
            }
    
    
    //This is my class constructor, but with a parameter to be changed and received!
            public cTemp(double sC)
            {
                mSaldoCarteira = sC;
            }
    
    
    //This is a property I created, to ensure that I can return the current balance of the person's wallet (when the program starts, the wallet will be initialized with a value, after taking the money that person needs from the wallet, a new value will take place on the wallet's balance (that's why there's 2 constructors).
            public String ToString2()
            {
                return mSaldoCarteira + " €";
            }
    [/SPOILER]

    The code above refers to the main class for the wallet's operations...

    [SPOILER]

    Code:
    public class cCarteira : cTemp //I'm inheriting all the operations from cTemp's class here!
        {
            double mQuantiaCorrente;
    
            public cCarteira() : base() //Since I've inherited everything from cTemp's class, I'm probably suposed to call the parent's constructor class, in order to apply any differences on the wallet's balance. Right?! x.x
            {
                mQuantiaCorrente = psaldoCarteira - totalEmMao;
            }
    
            public cCarteira(double sC) : base() //Here is where I'm absolutely not sure if this is supose to be here. Actually I'm almos positive it's not supose to be here...
            {
                mQuantiaCorrente = sC;
            }
        }
    [/SPOILER]

    The code above refers to the secondary class (cCarteira), which only has the purpose of changing the wallet's balance... This is what I need to solve, before I can move on.

    I'm eagerly awaiting for some answers to this. Thank you.

    Note: To get you a bit more clarified of what's going on, I can tell you that my program is about a vending machine (that sells only beverages), appart from the sales has other functions, but so far I got that covered. The vending part is done on a step by step basis, meaning, you have the vending machine in front of you, you need to insert coins, so 1st you open your wallet, an interface appears showing you your current balance and a few operations to do on your wallet (the one that matters is to take money from your wallet (only in coins, to make it easier)), after taking the money you have to close your wallet, passing through the same interface again, checking your current balance (after taking the money!), then the vending machine will know that a certain number of € is going to be used on it, so the products up to that sum will unlock and the user is allowed to pick the products (the products will lock again along the decrease of the balance on the machine), finally the user retrieves his products (beverages) and will take his change (if there's any).
    I hope that made it more clear than confusing. If you need, I can send my program via an uploader (to whomever wants to help me x.x).

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611

    Re: I can't understand what I'm missing on (base) constructor on C#

    I think it is quite simple and you are on the right track. You should change this line:
    Code:
    public cCarteira(double sC) : base()


    to
    Code:
    public cCarteira(double sC) : base(sC)
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width