What is a “method” in C# programming?

779 views

I am currently going through “Become a C# Developer” on LinkedIn Learning and watching this course “Understanding C# syntax”, the instructor – Bruce Van Horn – went on to explain properties but he never explained what is a method? I mean, what is a method? What is it used for? How do I know where to look for method?

Is this simply just a word – like in real world – a method to do something? E.g. completing a task using method 1 or method 2?

TL;DR: what is a method? What is it used for? How do I know where to look for method?

Also, I have Googled this using keyword, but no real good explanations come out of it that I understand.

In: Engineering

6 Answers

Anonymous 0 Comments

A property is just a fundamental datatype or a construct of said datatypes that are attached as an attribute of the object. You can view it, you can modify it, but it just kinda sits there. It doesn’t DO anything.

A method on the other hand is a function – it takes inputs, does stuff (possibly to or with the object’s own properties) and returns outputs. Maybe other objects, or the values of the object’s properties.

Objects usually have some special methods. One is a constructor, and one is a destructor – these are special methods called when an instance of that object is created, or destroyed/deleted/freed respectively.

If you as a person were an object, your properties would be “hair color” or “eye color”. Your methods would be “eat food” or “run”.

You are viewing 1 out of 6 answers, click here to view all answers.