can any one tell me whats wrong in this code?
-
using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }
hi
-
using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }
hi
-
using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }
hi
-
using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }
hi
Change this part of your code
if (_acctype = "savings" || _acctype = "current")
{
_acctype = value;
}
else
{
_acctype = "";
}to this
if (_acctype == "savings" || _acctype == "current")
{
_acctype = value;
}
else
{
_acctype = "";
}-Larantz-
for those about to code, we salute you
http://www.tellus-software.com -
what error message are you getting? Did you declare the constructor in your class?
happy coding!
iam getting identifier expected
hi
-
iam getting identifier expected
hi
OK, Can you do the following: 1. Take out System.Collections for time being 2. Add the default constructor like public Bank(){}. 3. Comment out all your properties get and set methods. 4. Start building the code and start uncommenting each of the properties and then see what error message you get and at what stage , this will enable to to understand the problem better. Sorry cann't help more than this because don't have IDE in front of me, Hope you sort out your problem,
happy coding!
-
using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }
hi
Just as an aside --
public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; }
These two functions have parameter names that hide the private members - so if you are trying to make the function use your actual balance instead of a balance that is passed in, they should be declared as: public int credit(_amount){/*code*/} and public int debit(_amount){/*code*/} And if you want the balance to actually be updated, you'll need to do _balance -= _amount; or _balance += _amount; (this is assuming that you actually do want it to be updated)
-
using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }
hi
-
using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }
hi
Ok, after looking at your code, AND the other replies, there are areas that do have real problems. LOGICAL ERROR: public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } In your test, you are assigning the strings to _acctype, what you accomplish will not be what you want, as _acctype will always be assigned the contents of value. QUESTIONABLE on what you are attempting to do: public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } you are overriding the internal private class variables _balance and _amount with what you pass in as _balance and _amount. Im not sure what you intended to do here. Is the class variable _amount needed? Are you trying to update _balance, or are you just attempting to deliver the would be changes just for the values or to update externally? -Later! -WB-
-
using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }
hi
you are getting the error because you are not specifying the data type for the method arguments:
public int credit(_balance , _amount)
{
return _balance + _amount;
}
public int debit(_balance , _amount)
{
return _balance - _amount;
}TRY:
public int credit(
int
_balance ,int
_amount)
{
return _balance + _amount;
}
public int debit(int
_balance ,int
_amount)
{
return _balance - _amount;
} -
iam getting identifier expected
hi
Visual Studio will show numbers at the left of your source lines for you, and the error messages it generates include file name and line number; look at the first error you have, go investigate that particular line, (try to) fix it and recompile. Until everything is OK. :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }