| | |
What's wrong with this program?
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 17
Reputation:
Solved Threads: 0
Now I still learning C#, and in one of the tutorials I found this program:
When I tried compile this program I received in line (marked by me as 1!) error :
Type Returning_a_Class_From_a_Method.MotorVehicleAdministration
already defines a member called 'RequestDateOfBirth' with the same parameter types which points to RequestDateOfBirth()
I think that error caused because of declaration
but I still can't find any solution to this. It's tutorial, but this program won't run. What I must do to correct error?
C# Syntax (Toggle Plain Text)
using System; namespace Returning_a_Class_From_a_Method { public class MVADate { private int dayOfBirth; private int monthOfBirth; private int yearOfBirth; public void SetDate(int d, int m, int y) { dayOfBirth = d; monthOfBirth = m; yearOfBirth = y; } public string ProduceDate() { string result = dayOfBirth + "/" + monthOfBirth + "/" + yearOfBirth; return result; } } public class MotorVehicleAdministration { public MotorVehicleAdministration() { birthdate = new MVADate(); } private string fullName; private MVADate RequestDateOfBirth(); private bool isAnOrganDonor; 1! private MVADate RequestDateOfBirth() { MVADate date = new MVADate(); Console.Write("Day of Birth: "); int d = int.Parse(Console.ReadLine()); Console.Write("Month of Birth: "); int m = int.Parse(Console.ReadLine()); Console.Write("Year of Birth: "); int y = int.Parse(Console.ReadLine()); date.SetDate(d, m, y); return date; } static void Main(string[] args) { MotorVehicleAdministration MVA = new MotorVehicleAdministration(); Console.WriteLine("To process a registration, enter the information"); Console.Write("Full Name: "); MVA.fullName = Console.ReadLine(); MVA.birthdate = RequestDateOfBirth(); Console.Write("Is the application an organ donor (0=No/1=Yes)? "); string ans = Console.ReadLine(); if (ans == "0") MVA.isAnOrganDonor = false; else MVA.isAnOrganDonor = true; Console.WriteLine("\n -=- Motor Vehicle Administration -=-"); Console.WriteLine(" -=- Driver's License Application -=-"); Console.WriteLine("Full Name: {0}", MVA.fullName); Console.WriteLine("Dateof Birth: {0}", MVA.birthdate.ProduceDate()); Console.WriteLine("Organ Donor? {0}", MVA.isAnOrganDonor); Console.WriteLine(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } } }
When I tried compile this program I received in line (marked by me as 1!) error :
Type Returning_a_Class_From_a_Method.MotorVehicleAdministration
already defines a member called 'RequestDateOfBirth' with the same parameter types which points to RequestDateOfBirth()
I think that error caused because of declaration
C# Syntax (Toggle Plain Text)
private MVADate RequestDateOfBirth();
•
•
Join Date: Apr 2008
Posts: 45
Reputation:
Solved Threads: 10
I think there's a couple of ways you could solve the problem you are having. One of the options you could use would be to make MotorVehicleAdministration a separate object.
The issue you were experiencing came from the fact that you had the RequestDateOfBirth declared twice. It didn't like that you had
private MVADate RequestDateOfBirth();
declared before
private MVADate RequestDateOfBirth()
{
...
}
I'm pretty sure you would have to do something like this in say...C++...but not C#. Even after fixing that issue, there were a lot of bugs in the code that dealt with accessibility issues with the variables all being declared private and then trying to access them from a static method.
C# Syntax (Toggle Plain Text)
using System; namespace Returning_a_Class_From_a_Method { public class MVADate { private int dayOfBirth; private int monthOfBirth; private int yearOfBirth; public void SetDate(int d, int m, int y) { dayOfBirth = d; monthOfBirth = m; yearOfBirth = y; } public string ProduceDate() { string result = dayOfBirth + "/" + monthOfBirth + "/" + yearOfBirth; return result; } } public class MotorVehicleAdministration { public MotorVehicleAdministration() { birthdate = new MVADate(); } private string fullName; private MVADate birthdate; private bool isAnOrganDonor; public void RequestDateOfBirth() { Console.Write("Day of Birth: "); int d = int.Parse(Console.ReadLine()); Console.Write("Month of Birth: "); int m = int.Parse(Console.ReadLine()); Console.Write("Year of Birth: "); int y = int.Parse(Console.ReadLine()); birthdate.SetDate(d, m, y); } public MVADate Birthdate { get { return birthdate; } } public bool IsOrganDonor { get { return isAnOrganDonor; } set { isAnOrganDonor = value; } } public string FullName { get { return fullName; } set { fullName = value; } } } public class Test { static void Main(string[] args) { MotorVehicleAdministration MVA = new MotorVehicleAdministration(); Console.WriteLine("To process a registration, enter the information"); Console.Write("Full Name: "); MVA.FullName = Console.ReadLine(); MVA.RequestDateOfBirth(); Console.Write("Is the application an organ donor (0=No/1=Yes)? "); string ans = Console.ReadLine(); if (ans == "0") MVA.IsOrganDonor = false; else MVA.IsOrganDonor = true; Console.WriteLine("\n -=- Motor Vehicle Administration -=-"); Console.WriteLine(" -=- Driver's License Application -=-"); Console.WriteLine("Full Name: {0}", MVA.FullName); Console.WriteLine("Dateof Birth: {0}", MVA.Birthdate.ProduceDate()); Console.WriteLine("Organ Donor? {0}", MVA.IsOrganDonor); Console.WriteLine(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } } }
The issue you were experiencing came from the fact that you had the RequestDateOfBirth declared twice. It didn't like that you had
private MVADate RequestDateOfBirth();
declared before
private MVADate RequestDateOfBirth()
{
...
}
I'm pretty sure you would have to do something like this in say...C++...but not C#. Even after fixing that issue, there were a lot of bugs in the code that dealt with accessibility issues with the variables all being declared private and then trying to access them from a static method.
•
•
Join Date: Feb 2008
Posts: 17
Reputation:
Solved Threads: 0
I didn't wrote this program. I find it on web pages tutorials from FunctionX. I am absolute beginer in Visual C# and so far I didn't found any book which is for absolute beginner (read: with no any contact with this programming).
Of course I found some books from which I was able to learn, but at some point this learning always stopped. On this web pages are true lessons for absolute beginners. But of course - from time to time - everyone can find some bugs...
But thanks for this answer...
Of course I found some books from which I was able to learn, but at some point this learning always stopped. On this web pages are true lessons for absolute beginners. But of course - from time to time - everyone can find some bugs...
But thanks for this answer...
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
then try the video training material at http://www.3dbuzz.com which is designed with people just like you in mind, and theres 3 sections all absolutely free for c#
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
![]() |
Similar Threads
- Can anyone figure out what is wrong in my program? (C++)
- Jumps into code on program end (Pascal and Delphi)
- Can't see the program execute (C++)
- Can any1 tell me whatz wrong in this program...this does not show the output!!! (C++)
- 2 errors in c++ program :-( (C++)
- Can someone tell me what wrong with this program it doesn't run (C++)
Other Threads in the C# Forum
- Previous Thread: Data encryption in C#
- Next Thread: how to create shortcuts?
Views: 365 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box button buttons c# chat check checkbox class client code color combobox control conversion csharp custom database datagridview dataset datetime degrees draganddrop drawing encryption enum excel file files form format forms ftp function gcd gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






