C# 中的方法隱藏是什麼?
方法隱藏也稱為影子。在影子中,子類可以使用父類的方法,而無需使用覆蓋關鍵字。子類有自己版本的相同函式。
使用新關鍵字執行影子。
我們看一個例子。
示例
using System;
using System.Collections.Generic;
class Demo {
public class Parent {
public string GetInfo () {
return "This is Parent Class!";
}
}
public class Child : Parent {
public new string GetInfo() {
return "This is Child Class!";
}
}
static void Main(String[] args) {
Child child = new Child();
Console.WriteLine(child. GetInfo());
}
}輸出
This is Child Class!
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP