Why doesn't the sum method in this section need static before it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why doesn't the sum method in this section need static before it?

I guess I am really just wanting to know more about putting static vs not putting static and what those terms mean

20th Jul 2016, 6:13 AM
Robert Jones
2 Answers
+ 2
When you press "Try it yourself", the Sum method does have static before it. Simply put, any methods called by the static Main method must be static as well. Hope this helps :)
20th Jul 2016, 11:56 AM
Jafca
Jafca - avatar
+ 2
look normally when in an object oriented language you call a method from a class you need an object to call it . but here in C# our Main method itself is a part of a Class and we already know that a program starts executing from Main method. so without its object how would you call it. thats why we use the word static before methods so that we can call them in our Main method . i hope u understand.
30th Jul 2016, 7:25 PM
Javeria Khan