Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

A question about methods

I have a question about methods, and that is what is the point of them. Is there anything cool that you can only do in a method because i'm pretty sure you can just put everything you had in your method into your main and it'll still work normally. Is there a difference? I would appreciate if someone could maybe explain this more in depth. Thanks!

Best Answer

  • Sl0thSl0th Member
    Accepted Answer

    Hey there

    First I just want to clarify that Main also is a method.

    There are a lot of uses for methods. It is impossible to program anything proper without them. I will have the details out for now, as you'll have to understand the concept of classes to fully grasp why methods are so vital.

    To give you a grasp of it, though, try to imagine how you'd do anything at all without them. Console.WriteLine() is a method. How would you print anything without it? C# has made the functionality for how to print something, and the way that you access it is by calling the method. Methods are so fundamental, because there is no behaviour at all without methods.

    I know that's a bit vague explanation. What you can think of them for now is as a way to avoid having to write the same code more than once. Say you are writing a program where as soon as the user writes something particular, you want something specific to happen. You could write out exactly what should happen every time you make a check for it, or you could simply make a method that defines it and then call that every time.

    Hope it makes sense.

Answers

Sign In or Register to comment.