Code:
public static string ValidateName ( string name )
{
string trimmedName = name.Trim();
if ( trimmedName.Length == 0 )
{
return "No text in the name";
}
return "";
}
1. The code above removes extra white space (This removes the possibility of having a length greater than 0 without actual characters). Then checks to see if the length is equal to 0. If so, sends a reply to a boolean method to be processed. If greater than 0 sends an empty reply.
Code:
public Account ( string inName, decimal inBalance )
{
if ( !SetName(inName) )
{
throw new Exception("Invalid name");
}
if(inBalance < 0 || > 10000)
throw new Exception("Invalid Balance");
else
this.balance = inBalance;
}
2. A call to a static method generates a call instruction in Microsoft intermediate language (MSIL). whereas a call to an instance method generates a callvirt instruction, which also checks for a null object references. However, most of the time the performance difference between the two is not significant. So it's slightly faster than non-static because it does less.
3.
Code:
public Account ( string inName)
{
if ( !SetName(inName) )
{
throw new Exception("Invalid name");
}
this.balance = 0;
}
4. the ToString method returns whatever value as a string.
Code:
protected string ToString(object obj)
{
return obj.ToString();
}
5.
Code:
public void TestBank()
{
Account acc = new Account("Kiryn");
Account acc1 = new Account("", 1337);
Account acc2 = new Account("Kiryn", -50);
Account acc3 = new Account("Kiryn");
acc3.payInFunds(50);
acc3.getBalance();
}
6.
Code:
private decimal limit;
Code:
public override bool WithdrawFunds ( decimal amount )
{
if (amount > limit)
{
return false ;
}
return base.WithdrawFunds(amount);
}
Code:
public decimal Limit {
get {
return limit;
}
set {
limit = value;
}
}
}
Edit: this took me like 20min bro. In the time you spent posting on the forums you could've had it done.