Skip to main content

Command Palette

Search for a command to run...

C# Methods

Published
•1 min read•View as Markdown
F

After receiving a Diploma degree in civil engineering. I have opportunities working in the positions in civil engineer on road and bridge ‘s company; As a engineer at iDECOVIETNAM Consultant Company, with a bachelor degree in civil engineering in BACHKHOA University, Practice certificates for transport construction engineering design, specialized in road, bridge and infrastructure (Earthwork, embankment, ground improvement); I am seeking for a new opportunity in construction. Flexible, ambitious, tenacious and resistant to stress, I adapt myself easily to any situation and I am of the opinion that there is no problem without solution.

A method is a block of code which only runs when it is called. You can pass data, known as parameters, into a method. Methods are used to perform certain actions, and they are also known as functions. Why use methods? To reuse code: define the code once, and use it many times.

Create a Method

A method is defined with the name of the method, followed by parentheses (). C# provides some pre-defined methods, which you already are familiar with, such as Main(), but you can also create your own methods to perform certain actions:

Example

class Program
{
  static void MyMethod() 
  {
    // code to be executed
  }
}

Example Explained

  • MyMethod() is the name of the method

  • static means that the method belongs to the Program class and not an object of the Program class. You will learn more about objects and how to access methods through objects later in this tutorial.

  • void means that this method does not have a return value. You will learn more about return values later in this chapter

16 views

More from this blog

FelixTran

12 posts

I am Civil Engineering, self taught Full Stack Web Developer from Tp.HCM, Viet Nam. I do a lot of things, and some of them you may even find interesting. 👨‍💻