10088人加入学习
(18人评价)
C#编程-第二季-面向对象-宇宙最简单2021最新版

制作完成于2021-10月20日 使用VS2019

价格 免费

class Program
{
    static void ShowList(List<int> list)
    {
        foreach (int temp in list)
        {
            Console.Write(temp + " ");
        }
        Console.WriteLine();
    }
    static void Main(string[] args)
    {
        List<int> list = new List<int>() { 56, 23, 894, 32, 5623, 32,4573 };

        //Console.WriteLine(list.Capacity);
        //list.Add(800);

        //Console.WriteLine(list[2]);

        //list.Insert(3, 800);


        //list.Remove(32);
        //ShowList(list);

        //list.RemoveAt(2);
        //ShowList(list);

        //增  删 改 查

        //Console.WriteLine(list.IndexOf(320));
        //Console.WriteLine(list.LastIndexOf(32));

        list.Sort();
        ShowList(list);

    }
}

[展开全文]

class Program

{

static viod Main(string[] args)

 {

 List<int> list = new List<int>() {321,654 987};

  list.Add(900);

  list.Add(6732);

 

  Console.Writeline(list[3]);

  list.Count;

  }

}

[展开全文]

class Program
{
    static void Main(string[] args)
    {
      StudentSt stu1 = new StudentSt(18, "小芳");
        StudentSt stu2 = new StudentSt(25, "小刚");

        stu2 = stu1;

        stu1.age = 30;
        stu1.name = "费伦";

        Console.WriteLine(stu2.age);
        Console.WriteLine(stu2.name);
    }
}

struct StudentSt
{
    public int age;
    public string name;

    public StudentSt(int age,string name)
    {
        this.age = age;
        this.name = name;
    }
}

[展开全文]

using System;

using System.Collections.Generic;

using System.Text;

 

namespace _09_抽象类

{

    public abstract class Enemy

    {

        private int hp;

        private int speed;

 

        public void Move()

        {

            Console.WriteLine("Move");

        }

        public abstract void Attack();

 

    }

}

[展开全文]

public T this[int index]{
get{
if(index<0 || index > count -1){
throw new Argumentout0fRangeException("参数超出范围了");
}
return data[index];
}
 

[展开全文]

//添加元素之前,先判断数组是否已经满 if (data.Length==count) { T[] temp = new T[count * 2]; for(int i =0; i< data.Length; i+){ temp[i]= data[i]; } data = temp; } data[count] = item;

[展开全文]

int [] myArr = {1,2,3,4};

try{
int temp = myArr[4];
}
catch (Index0utOfRangeException e){
//出现这个异常的时候,怎么处理
Console.WriteLine("出现了数组下标越界的异常");
}
catch (FieldAccessException e){
Console.WriteLine("出现 FieldAccessException的异常");
}
finally{
Console.WriteLine(""不管是否出现异常,都会执行");
)
 

[展开全文]

列表内部数据是使用数组进行储存的,一个空的列表内部会有一个长度为0的数组,当给列表中添加元素的时候,列表容量会扩大为4,如果添加第五个的时候列表的大小会重新设置为8,方式是创建一个容量为8的容量,复制容量为4的内容放到8里面加上新增容量,完成后删除原本为4容量的数组。如果添加第九个元素,列表容量会扩大为16(是成本增加的)当列表中的容量发生改变的时候,他会创建一个新的数组,使用Arry,copy()方法将就数组中的元素复制到新的数组中,为了节省时间,如果事先知道要存储的数据的个数,就可以利用列表构造函数指定列表容量大小,比如下面的List<int> Z=new List<int>(10);创建了一个容量为10的列表,当容量不够用的时候,每次都会按照原来容量的2倍进行扩容。我们可以通过Capacity属性获取和设置容量 intList.Capaity=100;
2,注意容量和列表中元素个数的区别,容量是列表中用于存储数据的数组的长度通过Capacity获取,列表中的元素是我们添加进去需要管理的数据,通过Count获取列表的遍历,

遍历列表有两种方式:
1、for循环,遍历所有的索引,通过索引访问列表中的元素for(int i=0;i<Z.Count;i++){}

2、foreach遍历
foreach(int i in Z){}

[展开全文]

静态存储 static 可以直接访问

接口 interface 

[展开全文]

结构体也是可以有构造函数的。

值类型是储存在栈里面的。

 

[展开全文]

实现接口,是实现抽象函数

实现接口,实现抽象函数

实现接口,实现抽象函数

实现接口,实现抽象函数

实现ni

[展开全文]

授课教师

SiKi学院老师

课程特色

下载资料(1)
视频(60)