2
Reply

Getting Started

Sam

Sam

Jan 25 2008 1:39 PM
2.9k
Hi,

I am just getting started (absolute beginner) as I need to learn a language for a little private project of my own, not a student (far too old) help with assignment or anything like that. I have looked around at free books videos etc and its OK but the  one thing in common is that the materials tend to gloss over a lot and get you to copy code without really knowing whats going on, so you see the results of "your" work but still left confused.

I started a book C# Step by Step and it is explaining things quite nicely but there are still a few things that are not fully explained or glossed over. I don't really want to get well into the book with more and more questions going around in my head.  So I would just like to check my understanding of whats going on and clarify 1 point in particular.

Its a simple simple program and I have added comments under the first method so I think I understand the flow and whats going on..

The code is::

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace DailyRate
{
    class Program
    {
        static void Main(string[] args)
        {
            (new Program()).run();
        }

        public void run()
        {
            double dailyRate = readDouble("Enter your daily rate: ");
            // Declares int dailyRate
            // Assigns to METHOD readDouble ((which is text above)
            // On execution goes to readDouble Method

            int noOfdays = readInt("Enter the number of days: ");
            writeFee(calculateFee(dailyRate, noOfdays));     
        }

        private void writeFee(double p)
        {
            Console.WriteLine("The consultant's fee is {0}", p * 1.1);
        }

        private double calculateFee(double dailyRate, int noOfdays)
        {
            return dailyRate * noOfdays;
        }

        private int readInt(string p)
        {
            Console.Write(p);
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        private double readDouble(string p)
       
        {
            Console.Write(p);
            // Writes readDouble  or p to Console
            // i.e Enter your daily rate
            string line = Console.ReadLine();
            // this reads response to question
            return double.Parse(line);
            // this parses from string to double
            // returns result to dailyRate and sets value
        }
    }
}
My query is around variable p
declared an int  double dailyRate = readDouble("Enter your daily rate: ");
Being a novice I thought this was set to enter etc
But looking at the Method is looks like the value it brackets is assigned p rather than the text, it is also the same for others and it also quotes string p in intellisense.
Is this the case?
Is this always the case if I name a method()
The book mentions variable p but doesn't explain where it is so its the only thing I can think of.

My apologies if this is too basic and I seem thick (which could be true) but  I just like to know what is really going on.

Thanks for reading it and if you have taken the time to respond.

No doubt the first of many.

sam

Upload Source Code  Select only zip and rar file.
Answers (2)