Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are Local functions in C# 7.0?
Local functions are private methods of a type that are nested in another member. They can only be called from their containing member.
Local functions can be declared in and called from −
Methods, especially iterator methods and async methods
Constructors
Property accessors
Event accessors
Anonymous methods
Lambda expressions
Finalizers
Other local functions
Example 1
class Program{
public static void Main(){
void addTwoNumbers(int a, int b){
System.Console.WriteLine(a + b);
}
addTwoNumbers(1, 2);
Console.ReadLine();
}
}
Output
3
Example 2
class Program{
public static void Main(){
void addTwoNumbers(int a, int b, out int c){
c = a + b;
}
addTwoNumbers(1, 2, out int c);
System.Console.WriteLine(c);
Console.ReadLine();
}
}
Output
3
Advertisements