封装、继承、多态、接口、枚举、委托、多线程、集合、事件、都明白了?

来源:互联网 发布:上海巨人网络 编辑:程序博客网 时间:2024/06/01 16:21

封装、接口、继承、多态、枚举、委托、多线程、集合、事件、都明白了?

并没有明白,还需要加深记忆,仅作记忆。源自msdnApi库,现整理合并以便查询。

封装前:

<span style="font-family:Microsoft YaHei;font-size:14px;">using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;class Square{    // 选择width字段,然后封装看下    public int width, height;}class MainClass{    public static void Main()    {        Square mySquare = new Square();        mySquare.width = 110;        mySquare.height = 150;                // 宽和高的输出值        Console.WriteLine("width = {0}", mySquare.width);        Console.WriteLine("height = {0}", mySquare.height);    }}</span>

封装后:(选择width字段 Ctrl R+E 应用并确定)

<span style="font-family:Microsoft YaHei;font-size:14px;">using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;class Square{    // 选择width字段,然后封装看下    public int width, height;    public int Width    {        get { return width; }        set { width = value; }    }}class MainClass{    public static void Main()    {        Square mySquare = new Square();        mySquare.Width = 110;        mySquare.height = 150;                // 宽和高的输出值        Console.WriteLine("width = {0}", mySquare.Width);        Console.WriteLine("height = {0}", mySquare.height);    }}</span>

接口:

0 0
原创粉丝点击