随笔分类 -  Coding / c#

摘要:virtual 使用 c#的方法,默认为非虚方法,如果一个方法被声明为 virtual (虚方法),则继承该方法的任何类都可以实现它自己的版本。 public class BaseEngineer { public virtual void Work() { Console.WriteLine("B 阅读全文
posted @ 2024-06-09 20:43 文心1225 阅读(65) 评论(0) 推荐(1) 编辑
摘要:1. Delegate 委托 在C#中,委托是一种引用类型,表示对具有特定参数列表和返回类型的方法的引用,即委托就是一种用来指向一个方法的类型变量,可以通过委托实例调用方法,关键字是 delegate。 // 声明一个委托 public delegate void MyDelegate(string 阅读全文
posted @ 2024-06-04 21:07 文心1225 阅读(384) 评论(0) 推荐(0) 编辑
摘要:1. IEnumerable namespace System.Collections: public interface IEnumerable { public IEnumerator GetEnumerator (); } public interface IEnumerator { pubi 阅读全文
posted @ 2024-06-03 20:20 文心1225 阅读(28) 评论(0) 推荐(0) 编辑
摘要:1. 隐式类型 c#允许使用 var 声明变量,编译期会通过初始化语句右侧的表达式推断出变量的类型。 // i is compiled as an int var i = 5; // s is compiled as a string var s = "Hello"; // a is compile 阅读全文
posted @ 2024-06-02 22:00 文心1225 阅读(12) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示