zoukankan      html  css  js  c++  java
  • [.net 面向对象编程基础] (23) 结束语

    [.net 面向对象编程基础] (23)  结束语
     

          这个系列的文章终于写完了,用了半个多月的时间,没有令我的粉丝们失望。我的感觉就是一个字累,两个字好累,三个字非常累。小伙伴们看我每篇博客的时间就知道了,有多少个凌晨23点才完成的。其实在日常工作中用起来虽然比较容易,但要是真正的写出来,又要写的让初学者能看明白,真不是一件轻松的事情,其中里面有好多示例都要考虑如何写才能通俗易懂。 

     

          写这个系列的文章,有很多也是参考了博客园和网上的文章,没有一一列举出原作者和URL,在此表示感谢和歉意。但是我可以保证,我没有纯复制粘贴过一篇文章,每写一节我都融入了自己的理解,耐心的写了每一个示例,力求不误导初学者。每一个示例都可以编译通过,正常运行。我想编程者都要有一颗OPEN的心。这样才能自己进步,也能让更多的人进步。 

     

          当有很多小伙伴还在拿着一个月3~5K的工资混日子的时候,有些人已经年薪30~50W(当然我并没有这么碉)。想一下,别人付出了多少,当你还在群里问别人类型怎么转换的时候,有些人已经在在研究架构和设计模式;当你天天抱怨程序员就是民工的时候,有些程序员开着豪车、住着别墅,身边带着N+1个妹纸(当然这些也不是我,我还在路上)。 我就想说不论你是什么职位,做什么工作,都有TOP

     

          这系列文章只是一个.Net面向对象的入门或者说是一个基础的文章,当然你弄懂了这些,才是打开设计模式和架构设计的钥匙。学会了这些,你可以去理抬头挺胸的去面试任何一家.net工程师。如果你学会了还没面试上,那只能说是Interviewer有眼无珠(如果还失败,那你来我们单位,^_^)当然如果有时间,我会继续写一些系列文章。

     

           最后我发一下我的博客签名“No pains,No gains.”没有付出就没有收获,祝小伙伴们都成为大牛!

     

    -------------------------------------------------------------------------------------- 

    为了不使这篇文件没具体内容,我把我最近招聘试题附上,有了上面的知识,百分百通关! 

    --------------------------------------------------------------------------------------

    C# 高级工程师 

    (编号:201505060129) 

    要求:a.判断对错,如错误,请说明错误原因;

          b.请将答案填写在答题卡上;

          c.要求30分钟内完成。

     

    1.以下类AppleTree和Apple、Tree是继承关系,下面写法是否正确

    public class Tree{ }
    public class Apple{ }
    public class AppleTree:Tree,Apple{}

    2.有以下类Tree 和 AppleTree, AppleTree 继承于Tree, 并调用,以下写法是否正确

    public class Tree    
    {
       public abstract Color LeafColor { get; }
    }
    public class AppleTree:Tree
    {
    public override Color LeafColor { get { return Color.Green; } } }

     3. 有以下接口Tree , AppleTree 继承于Tree并实现接口成员方法,以下写法是否正确 

    public interface Tree
    {
            void Leaf();
            void Flower();
    }
    public class AppleTree : Tree { void Leaf() { Console.WriteLine("The color is green !"); } }

     4.有类FujiAppleTree和 接口 Tree 、 AppleTree 以下写法是否正确

    public class Tree
    {
        Color Leaf { get; }
    }
    public interface AppleTree : Tree
    {           
        new  Color Leaf { get; }
    }
    public class FujiAppleTree:AppleTree
    {
        public Color Leaf { get { return Color.Green; } }
    }

    5.以下关于TreeType枚举定义,写法是否正确

    public enum TreeType:uint
    {
                Apple,
                Maple=1,
                Ginkgo
    }

    6.以下获通过使用委托调用方法,写法是否正确

    static void Main(string[] args)
    {                
         Console.WriteLine(GetTreeColor(TreeType.Ginkgo).Name.ToString());
    }
    public enum TreeType:uint { Apple,Maple, Ginkgo }
    public delegate Color GetTreeColor(TreeType treeType);
    private abstract class Tree { public static Color GetTreeColor(TreeType treeType) { switch (treeType) { case TreeType.Apple: return Color.Green; case TreeType.Maple: return Color.Red; case TreeType.Ginkgo: return Color.Yellow; default: return Color.Green; } } }

    7.以下代码实现一个自定义事件,事件触发过程为:午夜到来-》有小偷进入-》主人呼叫狗 -》 赶走小偷,其中Dog为事件接收类,Host为事件发送类,根据以下代码判断过程描述是否正确

    class Program
    {
            static void Main(string[] args)
            {
                Dog dog = new Dog();
                Host host = new Host(dog);           
                DateTime now = new DateTime(2008, 12, 31, 23, 59, 50);
                DateTime midnight = new DateTime(2009, 1, 1, 0, 0, 0);
                Console.WriteLine("Time... ");
                while (now < midnight)
                {
                    Console.WriteLine("Now: " + now);
                    System.Threading.Thread.Sleep(1000);   
                    now = now.AddSeconds(1);               
                }            
                Console.WriteLine("
     Thief: " + now);
                Console.WriteLine("The thief came.... ");
                dog.OnAlarm();  
            }    
    }
    class Dog
    {        
           public delegate void AlarmEventHandler(object sender, EventArgs e);      
           public event AlarmEventHandler Alarm;
           public void OnAlarm()
            {
                if (this.Alarm != null)
                {
                    Console.WriteLine("Wang wang!!");
                    this.Alarm(this, new EventArgs());   
                }
            }
    }
    class Host
    {
        void HostHandleAlarm(object sender, EventArgs e)
            {
                Console.WriteLine("Have caught the thief");
            }
            public Host(Dog dog)
            {
                dog.Alarm += new Dog.AlarmEventHandler(HostHandleAlarm);
            }
    }

    8. 以下代码输出结果为22,22,是否正确

    static void Main(string[] args)
    {
                int obj = 2;
                Test<int> test = new Test<int>(obj);           
                Test<string> test1 = new Test<string>(obj.ToString());
                Console.WriteLine((test.obj+2)+","+(test1.obj+2));
                Console.Read();
    }
    class Test<T>
    {
                public T obj;
                public Test(T obj)
                {
                    this.obj = obj;
                }
    }

    9. 以下代码输出结果为“39996:USA;16665:China;”是否正确 

    static void Main(string[] args)
    {
                List<Customer> customers = new List<Customer> {
                    new Customer {ID ="A",City ="New York",Country ="USA",Region ="North                 
                                  America",Sales =9999},
                    new Customer {ID ="B",City ="New York",Country ="USA",Region ="North 
                                  America",Sales =9999},
                    new Customer {ID ="C",City ="XiAn",Country ="China",Region ="Asia",
                                  Sales =7777},
                    new Customer {ID ="D",City ="New York",Country ="USA",
                                  Region ="North America",Sales =9999},
                    new Customer {ID ="E",City ="BeiJing",Country ="China",
                                  Region ="Asia",Sales =8888},
                    new Customer {ID ="F",City ="New York",Country ="USA",
                                  Region ="North America",Sales =9999}
             };
             var orderedResults = from cg in (from c in customers
                            group c by c.Regioninto cg
                            select new { TotalSales = cg.Sum(c => c.Sales), Region = cg.Key })
                            orderby cg.TotalSales descending
                            select cg;
    
                string result="";
                foreach (var item in orderedResults)
                      result +=  item.TotalSales + ":" + item.Region+";";
                Console.WriteLine(result);
                Console.ReadLine();
             }        
    }

     10. 以下程序调用部分执行后,通过反射执行方式是否正确

     //调用部分
     namespace ConsoleApplication1
     {
        class Program    
    {
    static void Main(string[] args) { string SpaceName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace; string ClassType = Console.ReadLine(); object obj = Assembly.GetExecutingAssembly().CreateInstance(SpaceName+".OranageTree", false); object obj2 = Type.GetType(SpaceName + ".OranageTree").GetMethod(ClassType + "Color").Invoke(obj, null); Console.ReadLine(); } } } //实现部分 namespace ConsoleApplication2 { public class OranageTree { public static void FruitColor() { Console.WriteLine("Oranage Fruit Color:Oranage"); } public static void LeafColor() { Console.WriteLine("Oranage Leaf Color:Green"); } } }

     

    C# 高级工程师  答题卡

    姓名

     

    应聘职位

     

    序号

    正确(Y)错误(N

    原因(如错误,请在此说明错误原因)

    1

     

     

    2

     

     

    3

     

     

    4

     

     

    5

     

     

    6

     

     

    7

     

     

    8

     

     

    9

     

     

    10

     

     

    ==============================================================================================  

     返回目录

     <如果对你有帮助,记得点一下推荐哦,如有有不明白或错误之处,请多交流>  

    如果本系列文章都掌握了,可以看一下 《.NET 面向对象程序设计进阶》 

    <转载声明:技术需要共享精神,欢迎转载本博客中的文章,但请注明版权及URL>

    .NET 技术交流群:467189533    .NET 程序设计

    ==============================================================================================   

  • 相关阅读:
    博客作业06--图
    博客作业05--查找
    博客作业04--树
    博客作业03--栈和队列
    博客作业2---线性表
    博客作业01-抽象数据类型
    C语言最后一次博客作业
    C语言第十次博客作业--结构体
    C语言第九次博客作业--指针
    C语言第八次博客作业--字符数组
  • 原文地址:https://www.cnblogs.com/yubinfeng/p/4593478.html
Copyright © 2011-2022 走看看