Calling method or function (C#)

calling-methods
In this chapter you will learn:

  • How to declare and call method in Main method?
  • How to declare and call static method in Main method?
  • How to implement method or function in programming?

After creating function, you need to call it in Main() method to execute. In order to call method, you need to create object of containing class, then followed bydot(.) operator you can call the method. If method is static, then there is no need to create object and you can directly call it followed by class name.

Programming Examples

Output

Enter your name:     Steven Clark

Enter Your City:      California

Enter your age:       47

===================================
Name:   Steven Clark
City:     California
Age:     47
==================================
__

If method is declared static then you can directly call the method without creating object of containing class.

Programming Example:

Output

Steven Clark
__

Summary

In this chapter you learned about how to call method or function in main method. You also learned how to use static method in C sharp programming. In next chapter you will learn more about how to use static method and variables.



Leave a Reply

Your email address will not be published. Required fields are marked *