Click here to Skip to main content
15,889,281 members
Home / Discussions / C#
   

C#

 
General[SOLVED] Re: socket problem: works in visual studio, not as release Pin
TimWallace1-Oct-09 8:34
TimWallace1-Oct-09 8:34 
GeneralRe: [SOLVED] Re: socket problem: works in visual studio, not as release Pin
Luc Pattyn1-Oct-09 8:41
sitebuilderLuc Pattyn1-Oct-09 8:41 
QuestionMethod not calculating properly‏ Pin
Marcus Farrugia1-Oct-09 5:09
Marcus Farrugia1-Oct-09 5:09 
AnswerRe: Method not calculating properly‏ [modified] Pin
harold aptroot1-Oct-09 5:22
harold aptroot1-Oct-09 5:22 
GeneralRe: Method not calculating properly‏ Pin
PIEBALDconsult1-Oct-09 15:31
mvePIEBALDconsult1-Oct-09 15:31 
AnswerRe: Method not calculating properly‏ Pin
Luc Pattyn1-Oct-09 5:34
sitebuilderLuc Pattyn1-Oct-09 5:34 
AnswerRe: Method not calculating properly‏ Pin
J4amieC1-Oct-09 6:32
J4amieC1-Oct-09 6:32 
AnswerRe: Method not calculating properly‏ Pin
Keith Barrow1-Oct-09 7:05
professionalKeith Barrow1-Oct-09 7:05 
Marcus Farrugia wrote:
I'm creating an asp.net Pizza order form using c# for a night school course


OK, I'm going to apologies in advance if the following is either to simple or too complicated. If you are going to use C# you should really look into object oriented design (lots of references around), but only when and if you are comfortable with control flow logic (loops and descision statements etc). Getting you head around this will save a lot of work in the long run, but it's daunting as you start out (or it was for me anyway Smile | :) )

You should condisder breaking some of your code down further into classes. A class is a way of gathering properties (e.g. Size) and methods (e.g. Add/Remove Toppings) into one logical place (often representing something in the real world). This is known as encapuslation and prevents any unwanted side-effects from other things happening if you do it correctly. e.g. in your example a mistake is causing the total to be incorrect.

For example:
If you create a class called Topping, you could create several of these. The topping might have a property called Description (e.g. Description = "Ham") and a set of prices for each size (there are several way to do this, e.g. have a property for each size, which is less good or consider using a Dictionary)

Now you could have Pizza class, this could have a List of Toppings, a Size (and a list of pizza-base prices for each size, just like the topping) an a calculate cost method. To calculate the cost, you take the pizza-base cost for the current size, and for each topping add it's cost according to the pizza size.

A good initial way to work out which classes, properties and methods you need is to write down what you want to achieve, nouns indicate classes or properties, verbs indicate a method is required.
e.g.

A pizza can come in different sizes and have several toppings added or removed as required. Calculate the cost of the pizza and show to the customer.

Note that you'll see the classes Pizza and Topping I sugested highlighted as well as the size property. Also highlighted are "Add[Topping]" and "Remove[Topping]", I haven't put these on the pizza class directly, though you could. I have suggested you create a property called Toppings which is a List of toppings (List<Topping> google up List<T> for more advice). The list itself has an Add & Remove methods, so you don't have to add them.

This seems like a chore, but 99% of the time it works easier. For example you could now add new types of topping easily or add stuff to save to a database. If you implement it well , new pizza sizes should be easy and the code you write should be more readable, robust & easy to adapt to new requirements (all of which are important when programming)!

Good luck with your course, and I hope you enjoy it. I'm jelous, I wish I could unlearn the stuff I have done, just so I could re-learn it! On the up side I suppose there are lots of cool new things being done in IT to find out about all the time. OMG | :OMG: I am such a geek!

CCC solved so far: 2 (including a Hard One!)

QuestionUploading pictures. Pin
Mix Wheels1-Oct-09 4:17
Mix Wheels1-Oct-09 4:17 
AnswerRe: Uploading pictures. Pin
Luc Pattyn1-Oct-09 4:22
sitebuilderLuc Pattyn1-Oct-09 4:22 
QuestionSearching a non-PrimaryKey column within a DataTable with a partial string. Pin
KCI-VA1-Oct-09 3:49
KCI-VA1-Oct-09 3:49 
AnswerRe: Searching a non-PrimaryKey column within a DataTable with a partial string. Pin
Eddy Vluggen1-Oct-09 10:16
professionalEddy Vluggen1-Oct-09 10:16 
QuestionRe: Searching a non-PrimaryKey column within a DataTable with a partial string. Pin
KCI-VA1-Oct-09 10:37
KCI-VA1-Oct-09 10:37 
AnswerRe: Searching a non-PrimaryKey column within a DataTable with a partial string. Pin
KCI-VA8-Oct-09 5:32
KCI-VA8-Oct-09 5:32 
QuestionWindows Forms: TreeView in SplitContainer flickers on Resizing the screen ar runtime Pin
Poornima Naik1-Oct-09 3:21
Poornima Naik1-Oct-09 3:21 
QuestionRemove program from Control panel using C# Pin
Ajithevn1-Oct-09 3:07
Ajithevn1-Oct-09 3:07 
AnswerRe: Remove program from Control panel using C# Pin
stancrm1-Oct-09 3:18
stancrm1-Oct-09 3:18 
QuestionRe: Remove program from Control panel using C# Pin
Eddy Vluggen1-Oct-09 3:48
professionalEddy Vluggen1-Oct-09 3:48 
AnswerRe: Remove program from Control panel using C# Pin
Ajithevn1-Oct-09 6:07
Ajithevn1-Oct-09 6:07 
GeneralRe: Remove program from Control panel using C# Pin
Eddy Vluggen1-Oct-09 10:07
professionalEddy Vluggen1-Oct-09 10:07 
QuestionBuild issue [modified] : SOLVED Pin
Mustafa Ismail Mustafa1-Oct-09 2:54
Mustafa Ismail Mustafa1-Oct-09 2:54 
AnswerRe: Build issue Pin
Vasudevan Deepak Kumar1-Oct-09 3:01
Vasudevan Deepak Kumar1-Oct-09 3:01 
GeneralRe: Build issue Pin
Mustafa Ismail Mustafa1-Oct-09 3:52
Mustafa Ismail Mustafa1-Oct-09 3:52 
AnswerRe: Build issue Pin
Keith Barrow1-Oct-09 3:05
professionalKeith Barrow1-Oct-09 3:05 
GeneralRe: Build issue Pin
Mustafa Ismail Mustafa1-Oct-09 4:04
Mustafa Ismail Mustafa1-Oct-09 4:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.