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