C# C# Basics (Retired) Console I/O Formatting Output

Ankit Biswas
Ankit Biswas
280 Points

Why we use static in the main method? and why we use " " ?

Why we use those?

CodeChallenge.cs
using System;
namespace treehouse.fitnesfrog
class program
{
    static void main()
    {

1 Answer

Hakim Rachidi
Hakim Rachidi
37,628 Points

I didn't really get your question but a static method can be call without any prerequisites (without instantiating a Program object (for more go to C# objects)).

In C# normal methods can only be call on there appropriate object. This object is an instance of the class in which the method is defined. But in some cases we don't want to instantiate a new object, we just want to make a call to a method to make a calculation or perform some sort of action, by example:

Console.WriteLine();

We don't need to instantiate a Console object, we just want to perform an action via WriteLine().

Imagine I have a Person class and I want to instantiate a new instance with your name.

  • To call StepForward I have to Instantiate a new instance because it wouldn't make sense to go one step further without a Person
class Person {
    ....
    public void StepForward() {
         // go one step further
    }

    ....
}

Person Antik = new Person();

Antik.StepForward();

In the case of the Main method we don't want a program object to be instantiated. Why? Because we don't need one. For more information C# objects.

Hope this helps;