I'v got with my program this far to start using top level code.
If you look at my scheme you can see the top level is program:
I need to know where should I put the exchangeCar, login, logout method.
I tried to put them in program.cs, but it gives me "cannot declare instance members in static class" error
I tried to put it in the form.cs but this gives me some inconsistent accessibility error.
I want to know where should I put the methods? Program.cs, Form.cs or create another superclass?
Thank you
Sam HobbsPosted Oct 4, 2010, 5:08 PM
Suthish NairPosted Oct 4, 2010, 4:03 PM
Its a static class library, all the methods are static.??
Moose PickardPosted Oct 4, 2010, 2:56 PM
I appreciate your posts, but this is all about inability, nothing else.
This topic, and so many others I have posted.
I have done almost all work on my program from my own reasoning, logic and from other sources.
So this should't be the area of accusations.
I have asked many questions, but the answers provided are riddles, Yoda's thing.
Read some books, do it the other way etc, but all miss the answer to the original question.
I asked simple questions provided with all evidence: scheme, flow etc (should be familiar to all programmers): .
"Where should I put this method?" and "Why this doesn't work?".
You can reread the topic and see for yourself that only little good info is provided.
The topic could have been only 2 post one.
This is an issue of miscommunication and not paying attention.
It just starts getting annoying, that is all.
I'm not new to the world of online forums, I know the unwritten rules.
But this experience is new for me.
I don't need any feedback to this post because my post is already offtopic.
This is not some prohibition, I'm no moderator, and am not that familiar with the rules.
Thank you
Mahesh ChandPosted Oct 4, 2010, 1:48 PM
You may be a single young guy but many of us here have familities, full time job and with a limited time, we try to help others for FREE. So keep in mind, get the hint and go do your work, which you suppoed to do.
We can only guide you. YOU ARE THE ONE WHO HAS TO DO THE ACTUAL WORK.
Moose PickardPosted Oct 4, 2010, 11:51 AM
The inability to answer simple questions.
I don't want riddles. I thank you for your reply but is of no use to me.
I know about basic scope, the methods are public.
I want to kow why does this work:
class CarRentalProgram {
public List<CarRental>CarRentals = new List<CarRental>();
CarRental carRental1 = new CarRental();
public void CarTEST () {
CarRentals.Add(carRental1);
carRental1.AddUser("Moose", "Pickard", [email protected]);
carRental1.AddCar("BMW", "E36", 5000);
}
}
And this doesn't:
class CarRentalProgram {
public List<CarRental>CarRentals = new List<CarRental>();
CarRental carRental1 = new CarRental();
CarRentals.Add(carRental1);
carRental1.AddUser("Moose", "Pickard", [email protected]); //This line gives me error
carRental1.AddCar("BMW", "E36", 5000); // This line gives me error
}
Mahesh ChandPosted Oct 4, 2010, 9:36 AM
I suggest you download and read this book:
Free Book: C# Programming for Beginners
After that, read more on classes here.
Understanding Classes in C#
Hope it helps!
Cheers!
Moose PickardPosted Oct 4, 2010, 9:16 AM
Actually I am already doing it, but with other names.
I chose to create another class with the methods - CarRentalProgram.
But one thing that troubles me is this error:
"...is a 'field' but is used as a 'type'".
I've got this code:
class CarRentalProgram {
public List<CarRental>CarRentals = new List<CarRental>();
CarRental carRental1 = new CarRental();
CarRentals.Add(carRental1);
carRental1.AddUser("Moose", "Pickard", [email protected]); //This line gives me error
carRental1.AddCar("BMW", "E36", 5000); // This line gives me error
}
I tried to instantiate some objects to test.
But the error I described is given when I set some properties of the objects.
What I did next is that I tried to put the code in a method. The error disappeared.
Why is that so that I can't use the methods of these objects outside of the class's methods?
Also you can see the List CarRentals I created.
When I'm typing the name in it doesn't give me autocomplete. But when I do it inside a method it does.
I am starting to see that there is some rule behind this.
What is this?
Thank you for your posts.
Mahesh ChandPosted Oct 4, 2010, 7:13 AM
So you should have a class called "Car" that represents a Car object. You should have a class called Cars or CarCollection that represents a collection of Cars. You can also have a class called CarHelper and this class can have all the cars related helper functionality including your exchangeCar method.
You are going to create an instance of Car and other needed instances usually on the Form class. It is usually the Form's loaded event handler.
Hope it helps!
Moose PickardPosted Oct 3, 2010, 4:58 PM
I have read MANY books about C#, OOP, Design Patterns, Java, C#, PHP etc,and this problem is spefic only to C#.
(I haven't figured out where the form.cs, program.cs are in the hierarchy)
All I want to know is where should I put my ExchangeCar method? I expect a simple answer.
I'll rephrase it. Where would you put it, if You had this arhitecture to work with?
I think the scheme is clear enough to make it understood that it is a program about CarRentals, and exchange cars is about exchanging CARS between CarRentals. By the way I have one form in my program. And to add more clarity - this is my personal project, I don't need the smoothness of the commercial project. This is just an experiment.
I have one part of the answer: not in the program.cs.
But the program.cs has the access point - the main method.
And now you clarified that form.cs should have only form related stuff.
But where do I create the instances then? For testing I mean.
I have seen in books that they are put in form.cs.
Thank you
Sam HobbsPosted Oct 3, 2010, 2:43 PM
I am sorry if this is confusing. This is basic to C# and to object-oriented languages such as C#. Therefore it is explained very well in many books. So instead of someone trying to explain it all for you, it would be better if you find something that someone has already written that explains it to many people. Find a book about C#. You might be able to find articles on this subject but you will certainly benefit from a book.
There are various methodologies for developing applictions, but I am not really familir with them. One way is to use a Data Access Layer (DAL) separate from the Business Logic Layer (BLL). There are many articles about that. Another way is using Entities, and there are many articles about that too. Visual Studio has support for Entities but I don't know anything more on the subject.
You should look for all the relevant articles that this web site offers. Look in Design & Architecture in C# and .NET and in .NET Best Practices.
Moose PickardPosted Oct 3, 2010, 10:33 AM
User logs in
The list of cars get rendered.
Now he checks the car he wants to rent.
The ExchangeCar method gets called from the form button which submitts the necessery variables.
This code is the highest level. It is basically CarRentalProgram class. It has CarRental objects, which have Car and User objects etc. You can see from the scheme? Can you see it? I can see "http://tempuri.org/tempuri.html" but it is in flickr.
Mahesh ChandPosted Oct 3, 2010, 9:19 AM