numberOfPlanets value

B44

Member
Joined
Jul 22, 2020
Messages
7
Programming Experience
Beginner
Hello,

I am new to learning C# and within the course the section that I am currently on is Method calls and Input. In this section I am unable to understand how the console is printing the values of numberOfPlanets without setting them first. I have an attached an image to help better understand this issue.

Thank you.
Screen Shot 2020-07-22 at 10.47.41 AM.png
 
In the future, please post your code in code tags instead of sending a screenshot.

Anyway what is happening above is called parameter passing. When you call VisitPlanets(3), the parameter numberOfPlanets is set to 3 and the method body is executed with that value.
 
In the future, please post your code in code tags instead of sending a screenshot.

Anyway what is happening above is called parameter passing. When you call VisitPlanets(3), the parameter numberOfPlanets is set to 3 and the method body is executed with that value.

sorry about the screenshot. Thanks for your response. I, however do not understand how the parameter numberOfPlanets is set to 3? and how is that parameter executing the value for the above parameters that is the VisitPlanets()
 
I, however do not understand how the parameter numberOfPlanets is set to 3?
Can you not see anywhere in that code that the number 3 is used?
 
Of course numberOfPlanets is defined somewhere. That's what a method parameter is. What do you think this is:

static void VisitPlanets(int numberOfPlanets)

I suggest that you read all the material about writing and calling methods and then read it again.
 
Of course numberOfPlanets is defined somewhere. That's what a method parameter is. What do you think this is:

static void VisitPlanets(int numberOfPlanets)

I suggest that you read all the material about writing and calling methods and then read it again.
Thanks for the input. the code does not show anywhere if numnberofPlanets is defined. I looked up several documentations and was unable to find information pertaining to this.
 
the code does not show anywhere if numnberofPlanets is defined.
Again, what do you think I underlined in my last post? That IS the parameter declaration.

I don't know what material you've been using to learn and whether that is part of the problem or it's just that your way of thinking is not conducive to programming but there's a link to a tutorial in my signature below that you might consider working through. The section on method parameters is here, so you might try looking at that first and then doubling back to the beginning.
 
Again, what do you think I underlined in my last post? That IS the parameter declaration.

I don't know what material you've been using to learn and whether that is part of the problem or it's just that your way of thinking is not conducive to programming but there's a link to a tutorial in my signature below that you might consider working through. The section on method parameters is here, so you might try looking at that first and then doubling back to the beginning.
Honestly, you are a rude human being. I don't think it is wise to take any advice from you. Just because someone is at the learning stage does not mean you judge them and respond rudely. Please do not respond anymore to this thread.
 
I don't think it is wise to take any advice from you.
As an aspiring C# programmer, it's fairly clear that you should not take advice from someone who's been doing it for 20 years, answering questions on it for 15 and received an MVP award from Microsoft for that online contribution for 10. Do you want to learn or do you not?
Just because someone is at the learning stage does not mean you judge them and respond rudely.
Anyone can judge anyone any time they want. I've encountered many hundreds of people at the learning stage - I've been at the learning stage myself - and the concept of a method parameter is not usually a challenge. It is what it is. You can pretend that that's how it is for everyone if you want but that's not going to help you learn. Either the material you're using is poor or, as I said, your way of thinking is not currently conducive to programming - not everyone is suited to everything and that's no crime - or both so, if you do want to learn, you ought to consider making a change to either or both. It's up to you what's more important to you: learning how to program or ensuring that you don't get criticised. If you think that ignoring my programming advice is a good option then it would seem that you've made your choice.
 
When someone chooses to characterise criticism as bullying, you know there's little hope of redemption. If you really think this is bullying (I doubt you really do as I've seen enough people protecting their ego to know the difference) then I hope for your sake that you never experience real bullying as it might break you. I will post no further to this thread but I don't like your chances of your getting help from others based on this attitude. I don't monitor who posts what though, so I may well post to any future threads you may start if I feel that I have something to contribute. It's your prerogative to ignore those posts or not.
 
Lets start over...

You have your main method which runs when your application starts :
C#:
        internal static void Main()
        {
            VisitPlanets(2);
        }
Notice that VisitPlanets is your static method you are calling, and this method takes a parameter of type int.

So when you say VisitPlanets(2); - you are passing that parameter of number 2 to the static method VisitPlanets.

Each time you call this method you will output to the console the contents of times you visited x amount of planets based of the int in numberOfPlanets which is your declaration. And this is what @jmcilhinney was trying to point out to you :
C#:
        public static void VisitPlanets(int numberOfPlanets)
        {
            Console.WriteLine($"You visited {numberOfPlanets} new planets.");
        }
Does this make sense now?

Frankly, only I recall what it was like to once be a starter programmer. I'm not going to say much in the way of how you've over reacted above. I know what its like to have once been a learner, and I recall being haggled by experienced programmers for not knowing something I clearly should have in my earliest days. When someone expects you to know something, and you don't, this is a sure sign that you are following a terrible programming guide or you are skipping the "boring chapters" for the sake of progressing that little bit further a little quicker. If this is what you are doing, its an injustice to yourself. Spend time learning the basics, and read as much documentation as you can possibly digest. As this is ultimately the best and only way to learn any language.

If you were following the getting started tutorials from Microsoft; ie. the ones in my signatures spoiler. You would never have needed to ask this question, because you would have learned this in the later chapters of their getting started guide to C#. Difficult as it often is. Try not to read to much into what people write back to you online. What's often meant as words of encouragement can sometimes come across condescending and that's because its easy to misunderstand someone when reading words on a screen.

You're overreacting too. I don't see anything wrong with the replies you received from JM. Yes his replies are a little blunt but necessary in this case. Take the criticism on the chest and up your game with your learning experience. If you continue to be nice, keep your cool, ask more questions, and ask for links to documentation covering the questions you are asking us. You will find he can be very helpful to progress this learning curve you're on.
 
Back
Top Bottom