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

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

价格 免费

public void Run(){

}

public void Stop(){

}

public float length(){

}

[展开全文]

创建对象

结构体不需要new

类需要new

 

 

[展开全文]

try{里面放可能出错的代码}

catch(FormatException e)

{

console.writeLine("")

n1 = convert.toint32(console.readline)

n2 = convert.toint32(console.readline)

}

 

[展开全文]

每一个类都是使用单独的文件来保存的

[展开全文]

class MyList<T>

{

  private T[] data = new T[0]; //data null

  //引用类型 new

  //MyClass mc;

}

[展开全文]

class ClassA<T>

{

  private T a;

  private T b;

  public ClassA(T a , T b)

  {

    this.a = a;

    this.b = b;

  }

  public string GetSum()

  {

  dynamic num1 = a;

  dynamic num2 = b;

  }

}

[展开全文]

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();

 

    }

}

[展开全文]

1、编写健壮性强的代码

[展开全文]

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(""不管是否出现异常,都会执行");
)
 

[展开全文]

授课教师

问问题加入A计划,有专门负责答疑的老师哦!!!

课程特色

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