• C#面试题


    记录一道面试题:

    猫叫了,老鼠逃跑了,主人醒了。

    public class Program
        {
            public delegate void CryHandler(object sender, CryArgs e);
    
            public class CryArgs
            {
                /// <summary>
                /// 声音内容
                /// </summary>
                public string Voice { get; set; }
    
                /// <summary>
                /// 声音强度
                /// </summary>
                public string VoiceLevel { get; set; }
            }
    
            /// <summary>
            /// 事物基类
            /// </summary>
            public abstract class AnyOne
            {
                /// <summary>
                ////// </summary>
                public abstract void Hear(object sender, CryArgs e);
    
                /// <summary>
                /// 名字
                /// </summary>
                public string Name { get; set; }
            }
    
            /// <summary>
            /// 主人
            /// </summary>
            public class Master : AnyOne
            {
                public Master()
                {
                    base.Name = "主人";
                }
    
                /// <summary>
                ////// </summary>
                public override void Hear(object sender, CryArgs e)
                {
                    Awake(e);
                }
    
                /// <summary>
                ////// </summary>
                private void Awake(CryArgs e)
                {
                    Console.WriteLine(string.Format("{0}听到猫{2}地叫\"{1}\",被惊醒了!", base.Name, e.Voice, e.VoiceLevel));
                }
            }
    
            /// <summary>
            /// 老鼠
            /// </summary>
            public class Mouse : AnyOne
            {
                public Mouse()
                {
                    base.Name = "老鼠";
                }
    
                /// <summary>
                ////// </summary>
                public override void Hear(object sender, CryArgs e)
                {
                    RunAway(e);
                }
    
                /// <summary>
                ////// </summary>
                private void RunAway(CryArgs e)
                {
                    Console.WriteLine(string.Format("{0}听到猫{2}地叫\"{1}\",被吓跑了!", base.Name, e.Voice, e.VoiceLevel));
                }
            }
    
            /// <summary>
            ////// </summary>
            public class Cat
            {
                private CryArgs cryArgs;
                public event CryHandler OnCry;
    
                public Cat()
                {
                    cryArgs = new CryArgs();
                }
    
                /// <summary>
                ////// </summary>
                public virtual void Cry(string voice, string voiceLevel)
                {
                    cryArgs.Voice = voice;
                    cryArgs.VoiceLevel = voiceLevel;
                    Console.WriteLine(string.Format("猫{0}地叫了一声:{1}!", voiceLevel, voice));
                    if (OnCry != null)
                    {
                        OnCry(this, cryArgs);
                    }
                }
            }
    
            public static void Main(string[] args)
            {
                Cat cat = new Cat();
                Master master = new Master();
                Mouse mouse = new Mouse();
    
                cat.OnCry += master.Hear;
                cat.OnCry += mouse.Hear;
    
                cat.Cry("眯眯眯", "大声");
    
                Console.ReadLine();
            }
        }
  • 相关阅读:
    CPU和GPU实现julia
    基于SURF特征的图像与视频拼接技术的研究和实现(一)
    验证码识别--type7
    机器视觉项目基础框架
    实现gabor filter的滤波
    神经网络研究项目--以工程师的视角
    集装箱项目
    基于海康监控的图像识别设计
    反人脸识别的思路和实现
    单向信息传输系统设计实现
  • 原文地址:https://www.cnblogs.com/tonymu/p/2889441.html
Copyright © 2020-2023  润新知