跳至主要內容
an istj’s zone

an istj’s zone

哥们要进化成程序猿

项目名称
项目详细描述
链接名称
链接详细描述
书籍名称
书籍详细描述
文章名称
文章详细描述
伙伴名称
伙伴详细介绍
自定义项目
自定义项目
自定义详细介绍
Coventry-Summary

1. Method

1.1 Coventry

知识点:

  1. 怎么创建一个方法?返回类型?

  2. 参数按值传递?按引用传递?(ref out in)

  3. Recursion?

  4. 变量作用域?

1.2 AIYC

  1. 方法的声明?调用?

  2. 怎么在方法里添加参数?调用带参数的方法?多参数方法?

  3. 可选参数(为参数设置默认值的情况)?

  4. 命名参数?

  5. 参数的传递。同Coventry

  6. 方法的重载,以及重载调用(能不能返回值类型不同参数类型相同?)

  7. 递归


XiaoXianYue原创大约 10 分钟C#大二下C#大二下
C#->more class

1. 析构函数

1.1 析构函数

构造函数是在实例化类时使用的,而析构函数则是在对象被销毁或删除时自动调用。

析构函数具有以下属性:

  • 一个类只能有一个析构函数。

  • 析构函数只能被自动调用。

  • 析构函数不带任何修饰符或参数。

  • 析构函数的名称与类名完全相同,然后带上波浪号(~)前缀。

例如:

class Dog
{
  ~Dog() 
  {
    // 要操作的逻辑代码
  }
}

XiaoXianYue原创大约 10 分钟C#大二下C#大二下
Design Patterns--Gof 02

4. 接上回的Adapter Pattern

4.2 何时使用Adapter Pattern?

When to use?

  • We need to use an existing class BUT it’s interface doesn’t correspond to what needed
  • We need to use an existing class together with other classes but there is no compatible interfaces in between

XiaoXianYue原创大约 6 分钟Python大二下Python大二下
C#->string & array

1. 数组

1.1 数组

C# 提供了许多内置的类来存储和操作数据。

数组(Array)就是其中的一种。

数组是一种用于存储数据集合的数据结构。你可以把它看作是一个同类型变量的集合。

例如,需要存储 100 个号码的情况,你可以考虑声明一个能存储 100 个元素的数组对象,而不是声明一百个变量。

数组的声明格式如下:数字类型[] 数组名称

int[ ] myArray;

XiaoXianYue原创大约 10 分钟C#大二下C#大二下
C#->class

1. 类和对象

1.1 什么是类

正如我们在前面的模块中所看到的那样,内置的数据类型用于在声明的变量中存储单个值。例如,int x 在一个名为 x 的变量中存储一个整型值。

在面向对象的编程中,类是一种数据类型,它定义了一组声明对象的变量和方法。

例如,要创建管理银行帐户的程序,则可以使用 BankAccount 类声明一个对象,该对象具有管理各个银行帐户所需的所有属性和方法,如余额,存钱和取款的方法等。

一个类就像一个蓝图。它定义了一个类型的数据和行为。类定义以关键字 class 开头,后面跟着类名。类体包含花括号里面的数据和操作。如刚才提到的 BankAccount 类:


XiaoXianYue原创大约 13 分钟C#大二下C#大二下
Anonymous Methods and Lambda Expressions

1. 匿名方法

  • 匿名方法与委托密切相关。
  • 匿名方法用于创建委托的副本
  • 匿名方法不能独立存在
  • 匿名方法的定义以委托关键字开始:
MessageHandler handler = delegate(string mes)
{
    Console.WriteLine(mes)
}
handler("hello Sherry!")
delegate void MessageHandler(string message)

XiaoXianYue原创大约 4 分钟C#大二下C#大二下
Delegates and Event

1. Delegate 简介

  • 回调函数是程序指定并以某种方式 "注册 "的函数,然后被另一个程序调用 -

  • C/C++ 我们可以通过函数指针实现回调函数

  • C# -我们可以将方法引用封装在委托中

  • 在 C# 中,委托被视为一种引用类型,与类类型类似

  • 操作符 new 用于创建委托的新实例

  • 委托是对类中方法的安全引用类型

1.1 使用委托


XiaoXianYue原创大约 7 分钟C#大二下C#大二下
Generics

1. Boxing and Unboxing

Boxing is the process of converting a value type to the type object. Unboxing extracts(提取) the value type from the object

image-20240506142602009

Boxing is implicit隐性的; unboxing is explicit显性的

1.1 Boxing


XiaoXianYue原创大约 5 分钟C#大二下C#大二下
Interface

1. Object -> Person -> Employee/Client

1.1 Upcasting

image-20240506093638933

Same upcasting from Employee/Client to Object, as Object is the base class.

将 Employee/Client 上传到 Object 也是一样,因为 Object 是基类。

1.2 Downcasting


XiaoXianYue原创大约 5 分钟C#大二下C#大二下
Intheritance

• Inheritance is a way that we can re-use behaviours from classes and just modify the bits we need to make new ones

• Inheritance lets a class pick up behaviours from the class which is its parent

1. 继承的实现代码:

using System;
class Person
{
    public string Name { get; set; }
    public Person(string name)
    {
        Name = name; 
    }
    public virtual void printname()
    {
        Console.WriteLine(Name);
    }
}
class Employee : Person
{
    public int Id { get; set; }
    public Employee(string name, int employeeId):base(name)
    {
        Id = employeeId;
    }
    public override void printname()
    {
        base.printname();
        Console.WriteLine(Id);
    }
}
class Program
{
    static void Main(string[] args)
    {
        Person person = new Person("John");
        person.printname();
        Employee employee = new Employee("John",12345);
        employee.printname();
    }
}

XiaoXianYue原创大约 4 分钟C#大二下C#大二下