Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

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;