The concept of function within a function, like we normally do inside a class.
We will create a method GetName() .
The code will look like the following.
static void Main(string[] args) { Console.WriteLine("Name is: " + GetName()); } public static string GetName() { return "Name"; }
Next, we need to add more , will create Function called GetFullName() , will call 2 methods GetFName() and GetLName.
This result will be added to the GetFullName() and the complete result will be returned.
The main point here is that if we create a public method to concate our string togather, it will be globally available. If we create a private method, the method will be available to other methods as well, which is not required. So, what we will do is create the method as a sub-method within the GetFullName function. This will be created like any other normal function. So, the code will look like the following.
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Console.WriteLine("Full Name is: " + GetFullName()); } public static string GetFullName() { var FullName= GetFName() + " " +GetLName(); return FullName; string GetFName() { return "First Name"; } string GetLName() { return "Last Name"; } } }
we have created another two methods GetFName() and GetLName() within a function to return FullName().