So the code is this but I can't figure out the problem. I included the error alongside with it.

using System;

public class SavingAccount
{
   public static decimal interestRate = 0.02M;

   public string Name { get; set; }
   public decimal Balance { get; set; }

   public SavingAccount(string n)
   {
      Name = n;
   }

   public SavingAccount(string n, decimal b)
   {
      Name = n;
      Balance = b;
   }

   public void DisplayInfo()
   {
      Console.WriteLine("Account name: {0}\nAccount balance: {1}\nInterest Rate: {2}", Name, Balance, interestRate);
   }
}

public class Testing
{
   public static void Main(string[] args)
   {
      SavingAccount acct1 = new SavingAccount("Peter Chen");
      SavingAccount acct2 = new SavingAccount("Al Molin", 5000m);
      acct1.DisplayInfo();
      Console.WriteLine();
      acct2.DisplayInfo();
      Console.WriteLine();
      Console.WriteLine("Changing interest rate to 3%");
      SavingAccount.interestRate = 0.03m;
      acct1.DisplayInfo();
      Console.WriteLine();
      acct2.DisplayInfo();
      Console.WriteLine();
   }
}

Error 1 'Main': member names cannot be the same as their enclosing type

Any idea what the problem is. I looked through it a hundred times.

Recommended Answers

All 4 Replies

I don't get that error. Try cleaning the build and rebuilding.

You must have a problem somewhere else, because I took your code as is, and it compiled and ran fine. Hope this helps and good luck.

how do i clean a build, because i went to BUILD > clean solution > than hit f7 again to rebuilt but nothing happened

Are you missing any part of the codes....? Or any typo error in your code that the pasted sample doesn't have?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.