C# 基础: new 和 overrider 的区别
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
//contact ct = new contact(); //抽象类
class1 ct1 = new class1();
class2 ct2 = new class2(); contact ct3 = new class1();
contact ct4 = new class2();
ct1.prinf();
ct2.prinf();
ct3.prinf();
ct4.prinf(); //int i = System.Console.Read();
//string str = System.Console.ReadLine();
//System.Console.Read(); System.Console.ReadLine();
} abstract public class contact
{
public virtual void prinf() //关键字virtual
{
Console.WriteLine("这是虚方法");
} }
public class class1 : contact
{
public override void prinf() //关键字override
{
Console.WriteLine("这是新的方法");
} } public class class2 : contact
{
public new void prinf() //关键字new
{
Console.WriteLine("这是另一个新的方法");
} } }
}
运行结果如下:

C# 基础: new 和 overrider 的区别的更多相关文章
- [C#基础]ref和out的区别
在C#中通过使用方法来获取返回值时,通常只能得到一个返回值.因此,当一个方法需要返回多个值的时候,就需要用到ref和out,那么这两个方法区别在哪儿呢? MSDN: ref 关键字使参数按 ...
- Java基础-ArrayList和LinkedList的区别
大致区别: 1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构. 2.对于随机访问get和set,ArrayList觉得优于LinkedList,因为Lin ...
- C++_基础_C与C++的区别2
内容: (1)C++中的函数 (2)动态内存 (3)引用 (4)类型转换 (5)C++社区对C程序员的建议 1.C++中的函数1.1 函数的重载(1)重载的概念 在同一个作用域中,函数名相同,函数的参 ...
- Python基础学习Day6 is id == 区别,代码块,小数据池 ---->>编码
一.代码块 Python程序是由代码块构造的.块是一个python程序的文本,他是作为一个单元执行的. 代码块:一个模块,一个函数,一个类,一个文件等都是一个代码块. 而作为交互方式输入的每个命令都是 ...
- Hadoop(分布式系统基础架构)---Hive与HBase区别
对于刚接触大数据的用户来说,要想区分Hive与HBase是有一定难度的.本文将尝试从其各自的定义.特点.限制.应用场景等角度来进行分析,以作抛砖引玉之用. Hive是什么? Apache Hive是 ...
- js基础--substr()和substring()的区别
最近做项目的时候,字符串截取一直用的是substr()方法,有时候需要截取的内容是中间部分的话就很麻烦,需要分两次,第一次截取前半部分,第二次在第一次的基础上截取后半部分.写了几次之后总觉得没对,应该 ...
- Java基础-final和static的区别
很多时候会容易把static和final关键字混淆,static作用于成员变量用来表示只保存一份副本,而final的作用是用来保证变量不可变.看下面这个例子: public class Test { ...
- [jquery]基础篇--this与$this区别
参考: http://www.cnblogs.com/hannover/p/4109779.html 1.JQuery this和$(this)的区别 相信很多刚接触JQuery的人,很多都会对$(t ...
- C++_基础_C与C++的区别
内容: (1)C++简介和编程的基本变化 (2)命名空间的概念和使用 (3)结构体.联合.枚举的不同 (4)布尔类型 以及 运算符别名 (5)函数的重载.缺省参数.哑元以 及内联 1.简介和编程的基本 ...
随机推荐
- Create a DAC from a microcontroller's ADC
Few microcontrollers include a DAC. Although you can easily find an inexpensive DAC to control from ...
- GNU 是什么?
https://www.gnu.org/ GNU 是什么? GNU is a Unix-like operating system that is free software—it respects ...
- Assignment (HDU 2853 最大权匹配KM)
Assignment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- PHP:同一件事,有太多的方式
背景 刚接触PHP,发现PHP做一件事有太多的方式,挺灵活的,这或许是PHP的一种设计哲学,也有可能是语言演化的结果,下面举几个例子. 几个例子 在web中嵌入PHP代码. <?php ?&g ...
- 从两个TIMESTAMP中获取时间差(秒)
When you subtract two variables of type TIMESTAMP, you get an INTERVAL DAY TO SECOND which includes ...
- opencv CxImage 互转 (Mat)
//to Mat CxImage img; img.Load("C:\\f.jpg"); uint8_t* buf=NULL; int32_t len=0; bool rs =im ...
- 写的一个split函数
vector<string> strsplit(const string& str) { vector<string> vec; string sstr1=str, s ...
- C#常见算法题目
//冒泡排序 public class bubblesorter { public void sort(int[] list) { ...
- SQL Server之RAID简介
一: RAID简介 RAID(Redundant Array of Independent Disk 独立冗余磁盘阵列)是一项数据保护策略. 二: RAID的几种常用级别 1. RAID 0: 通过并 ...
- HTML5移动web横屏字体变大
html{ -webkit-text-size-adjust:none; -ms-text-size-adjust:none; -moz--text-size-adjust:none; text-si ...