C# 7.0 中的區域性函式是什麼?
區域性函式是型別的一種私有方法,巢狀在另一個成員中。它們只能從其包含的成員中呼叫。
區域性函式可以在以下位置宣告並呼叫:−
方法,尤其是迭代器方法和非同步方法
建構函式
屬性訪問器
事件訪問器
匿名方法
Lambda 表示式
解構函式
其他區域性函式
示例 1
class Program{
public static void Main(){
void addTwoNumbers(int a, int b){
System.Console.WriteLine(a + b);
}
addTwoNumbers(1, 2);
Console.ReadLine();
}
}輸出
3
示例 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();
}
}輸出
3
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP