老师的整个课件的示例代码在哪里下载啊

来源:8-1 课程总结

Heron_Wang

2018-07-26 23:09

如题,我想照着再敲一遍,但是视频里代码翻的太快了,好难捕捉啊 !!!

写回答 关注

4回答

  • 慕运维2414439
    2018-08-08 08:21:02
    已采纳

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ces
    {
        class Program
        {
            delegate void mmd(); //声明一个卖萌大赛委托
            static void Main(string[] args)
            {
                 /*
                Pet[] cry = new Pet[] { new Dog("小狗"), new Cat("小猫"), new Dog("小狗1") };
                for (int x = 0; x < cry.Length; ++x)
                {
                    cry[x]++;
                    cry[x].speak();
                    cry[x].AVG();
                }

                Cat c = new Cat("Tom2");
                c.speak();
                c.fishing(); //输出技能
                c.tree();
                Console.WriteLine();
                Dog.NUM();

                Dog d1 = new Dog("Tom");
                d1.speak();
                Cat c1 = d1;  //把小狗变小猫
                c1.speak();
              /
               var dogCage=new Cage<Dog>(1); //<放入宠物类型>
              dogCage.PutIn(new Dog("A")); //(new Dog("")调用宠物院里的宠物名字)
               dogCage.PutIn(new Dog("B"));
                var dog = dogCage.TakeOut(); //取出笼子里的狗,不取就没法出现被隐藏了
               dog.PrintName();  //取出的宠物名字是
               
              
                var dog = new Dog("F");
                dog.lsHappy<Person>(new Person()); //<声明的人变量>后面是实列化new Person()相当于Person person=new Person();
                dog.lsHappy<int>(3); //当狗看见3开心
               
                Labrador dog = new Labrador("小狗A");
                dog.Act(new SitDogCmd()); //实列输出技能并用act引用
            //列表:List
               List<Dog>  list = new List<Dog>();
                list.Add(new Dog("C"));
                for(int i=0;i<list.Count;++i){list[i].PrintName();}
                //字典:Dictionary
                Dictionary<string,Dog> dic = new Dictionary<string, Dog>();
                dic.Add("A",new Dog("小狗2号")); //ADD添加 数量Count  删除Remove 访问[Key]
                dic["A"].PrintName();
               
                  //栈:Stack
                Stack<Pet> stack = new Stack<Pet>(); //栈后面的<>指定类然后是实列化
                stack.Push(new Dog("狗A"));
                stack.Push(new Cat("猫A"));
                stack.Peek().PrintName();

                //队列:    Queue  //先进先出类似2端开口 出队Dequeue 入队Enqueue
                Queue<Pet> queue = new Queue<Pet>();
                queue.Enqueue(new Dog("小狗B1"));
                queue.Enqueue(new Dog("小狗B2"));
                Pet pet = null;
                pet = queue.Dequeue();
                pet.PrintName();
                pet = queue.Dequeue();
                pet.PrintName();

                mmd del = null;
                Dog dog1 = new Dog("小狗卖萌");
                Cat cat1 = new Dog("小狗卖萌");
                del = dog1.MM;
                del += cat1.MM;  //del+= 相当于第一个加上第二个并且自动换行
                del();  //输出delegate委托
                */
                KF c1 = new KF();  //实列化一个客服
                KF c2 = new KF();
                Dog.XCW += c1.tz;  //把客服赋值给XCW委托事件,然后用委托事件判断是否有新的宠物
                Dog.XCW += c2.tz;  //因为要先声明才能赋值判断否者是空
                Dog dog = new Dog("哈士奇");
                 Console.ReadLine();
            }
        }
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ces
    {
       
        interface skill  //本领
        {
            void fishing();  //fishin捕鱼
        }
        interface climb
        {
            void tree();
        }
        public abstract class DogCmd
            {
             public abstract string GetCmd();//声明GetCmd方法抽象方法abstract 不用函数体只能被继承修改
             }  //定义技能
        public class SitDogCmd:DogCmd
        {
            public override string GetCmd()
            {
               return "坐下"; //return还回  还回一个坐下的参数给GetCmd()
            }
        }  //什么技能
        public interface lDogLearn<C>where C:DogCmd //限制c这个接口只能接受DogCmd相关的技能
            {
            void Act(C cmd);
             }  //声明泛型接口来学技能
        public abstract class Pet  //abstract抽象化使相当于不存在
        {
            public string NAME;  //在父类中声明在派生类中base(继承对象)
            public Pet(string name)
            {
                NAME = name;
                age = 0;
            }
            public abstract void speak();
            public int age;
            public static Pet operator ++(Pet pet)
            {
                ++pet.age;
                return pet;
            }
            public void AVG()
            {
                Console.WriteLine("今年:" + age + "岁");
            }
            public void PrintName()
                {
                   Console.WriteLine("宠物的名字是"+NAME);
                 }
            public abstract void MM();
        }
        public class Dog : Pet
        {
            public static int Nom; //声名Nom为整数的静态
            public static void NUM()
            {
                Console.WriteLine("现在有几条狗:" + Nom);  //用静态输出打印的狗
            }
            public Dog(string name) : base(name)
            {
                ++Nom; //每赋值一个名字就加一条狗
                if (XCW != null)  //判断当xcw不为空时还回给XCW新宠物
                {
                     XCW();
                }
            }
            public override void speak()
            {

                Console.WriteLine(NAME + "汪汪");
            }
            public void lsHappy<T>(T target)//where T:class //泛型方法  //约束只能用引用类型所以int会报错
                {
                    Console.WriteLine("开心"+target.ToString()); //就是将该对象变成字符串,例如你传进来一个Cat类的对象cat,他就会将cat这个对象以字符串形式表现出来
                }
             public override void MM()
            {
              Console.WriteLine("哈士奇萌萌大赛");
             }
            public delegate void XC(); //声明事件
            public static event XC  XCW; //限制事件
        }
        public class Cat : Pet, skill, climb
        {
            public void fishing()
            {
                Console.Write("捕鱼");
            }
            public void tree()
            {
                Console.Write("爬树");
            }
            public Cat(string name) : base(name)
            {
            }
            public override void speak()
            {

                Console.WriteLine(NAME + "喵喵");
            }
                    //用自定义方法可以转换类型括号是要转换对象,必须不加保护级别不抽象
              public static  implicit operator Cat(Dog dog)
                {
                  return new Cat(dog.NAME);
                 }
                     public override void MM()
            {
              Console.WriteLine("无辜看着你");
             }
        }
        class Person //定义一个人的类当狗看见人开心
            {
            }
        public class Labrador : Dog,lDogLearn<SitDogCmd>  //泛型<>接受上文声明的技能
        {
                public Labrador(string name):base(name)
                {
                }
                  public void Act(SitDogCmd cmd) //实现一个泛型接口
                  {
                Console.WriteLine(cmd.GetCmd()); //输出技能
                  }
        }
        public class KF  //定义一个顾客类
        {
            public void tz()
                {
                 Console.WriteLine("有新的宠物来了");
                 }
         }     
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ces
    {
        public class Cage<T>
        {
            T[] array;  //宠物
            int num;   //声明输入宠物的数量
            readonly int Size;  //笼子数量

            public Cage(int n)
            {
                Size = n; //赋值给笼子数量
                num = 0;  //宠物初始为0
                array = new T[Size]; //把笼子给宠物
            }
            public void PutIn(T pet)
            {
                if (num < Size)
                {
                    array[num++] = pet;
                }
                else
                {
                    Console.WriteLine("笼子不够,放不下");
                }
            }
            public T TakeOut()  //取出宠物
            {
                if (num > 0)
                {
                    return array[--num]; //取出一只就减一个
                }
                else
                {
                    Console.WriteLine("笼子是空的");
                    return default(T);
                }
            }
        }
    }

    上把我看了在码的泛型方法那简直崩溃


    Heron_...

    非常感谢!!!

    2018-08-08 10:09:30

    共 1 条回复 >

  • kming
    2019-03-19 15:14:36

    这些代码难道不该是一起跟着打的吗,光下载下来有什么用。。。

  • 慕运维2414439
    2018-08-08 08:23:37

    老师是按他自己讲的所以没有下载地方不过上面的是我看完老师码完了所有课程的(注解我有的理解错误)

  • Heron_Wang
    2018-07-26 23:10:26

    哪里下载?

C#面向对象编程

本系列教程主要是,带你学习C#面向对象编程的编程思想、编程技巧

68857 学习 · 153 问题

查看课程

相似问题