About functions & methods

In C# it may be no different but do not say they’re the same, you’ll confuse a lot of people that came from different programming languages or the ones that started with C# and then went for another programming language.

talking in javascript which is the first logic-based programming language most people may have started with, a method is defined within an object, an object is a data type that contains information a method example is

obj = {
    race : "Cat",
    name : "Snow",
    Eat() {
        console.log("Snow is eating cat food")
    }
}

The method is Eat() and can be called by saying

obj.Eat() 

Now a function is what is defined anywhere but an object so my guess as a beginner in C# that all the “Functions” in C# are methods in the main scope public class, anyways here is an example of a function in javascript.

function Eat() {
    console.log("Someone is eating!")
}

Eat() // Prints out Someone is eating in the console

Now I’m just saying that even if C# had the idea of methods and functions are the same that does not mean it is in general.

P.S. You can test the code in the inspect elements option by Right-Click anywhere in the screen, Inspect Elements, click on Console at the place that popped up then copy and paste any of my code there.

Privacy & Terms