In C# how do you call one method from another method where both method are inside of the same class?
Experience Level: Junior
Tags: C#
Answer
When both methods reside inside of the same class, for calling method you just need to write its name followed by rounded brackets. If the method has any parameters, then these parameters need to be provided inside the brackets.
In the following example first the method WriteHello is called with no parameters. Then the method WriteMessage is called with two parameters. The first parameter contains the string "Hello" and the second parameter contains the string "World". The method WriteMessage accepts these two strings and writes each of them on a separate line.
Related C# job interview questions
What is 'return' keyword used for in C#?
C# JuniorWhat is 'this' keyword used for in C#?
C# JuniorWhat is an attribute in C#?
C# JuniorWhat must every method have in C#?
C# JuniorWhat do you know about methods in C#?
C# Junior